-
Notifications
You must be signed in to change notification settings - Fork 808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jetpack: Sync when an attachment is added to a post for the first time #10096
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
This is automated check which relies on Generated by 🚫 dangerJS |
@@ -9,8 +9,10 @@ public function init_listeners( $callable ) { | |||
add_action( 'edit_attachment', array( $this, 'send_attachment_info' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to suppress edit_attachment
activities when we know its an attach_attachement activity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick change since 6.5 is now behind us.
/** | ||
* Fires when an existing attachment is added to a post for the first time | ||
* | ||
* @since 6.5.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since 6.5 is out, you'll need to update this to 6.6.0 I'm afraid!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No prob, no big rush on this one!
Caution: This PR has changes that must be merged to WordPress.com |
Caution: This PR has changes that must be merged to WordPress.com |
$this->post->post_parent = 0; | ||
$modified_attachment = clone $this->post; | ||
$modified_attachment->post_parent = 1000; | ||
do_action( 'attachment_updated', $this->post->ID, $modified_attachment, $this->post ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of calling this do_action directly can we call the wp_insert_post with the expected parameters here?
This would help test that it would work across different version of WP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests really well!
There's still a few small things to address.
* Previously this action was synced using jetpack_sync_save_add_attachment action. | ||
*/ | ||
do_action( 'jetpack_sync_save_update_attachment', $attachment_id, $attachment ); | ||
do_action( 'jetpack_sync_save_update_attachment', $attachment_id, $attachment_after ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to include the old docblock as well
@enejb @jeherve @roccotripaldi would you mind taking another look? Thanks! |
$attach_attachment_event = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_save_attach_attachment' ); | ||
$update_attachment_event = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_save_update_attachment' ); | ||
$add_attachment_event = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_save_add_attachment' ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets also check that we have all the data that will make it so possible that the attachment is stored on the .com side as expected.
|
||
function process_update( $attachment_id, $attachment_after, $attachment_before ) { | ||
// Check whether attachment was added to a post for the first time | ||
if ( 0 === $attachment_before->post_parent && 0 !== $attachment_after->post_parent ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be checking here if the attachment has changed?
Is it also possible for the attachment to be removed?
Does that ever happen?
Caution: This PR has changes that must be merged to WordPress.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in the PR look good and I was able to see the new activity show up on the .com side.
Before merging it lets update the .com side first so that we don't potentially loose data for folks running the latest master.
* Readme: add boilerplate for next release, 6.6 * Add 6.5 to the changelog.txt file * Set boilerplate testing list for 6.6 * Readme: update stable tag to 6.5 * Add bullets to 6.5 changelog items * Readme: add link to previous changelogs This will help folks who want to know more about past releases, while keeping the readme.txt short so as to not overwhelm translators and site owners only looking for information about the last release. * Changelog: add information at the top of the changelog file. * Changelog: add #10054 * Changelog: add #10078 * Changelog: add #10079 * Changelog: add #10064 * Changelog: add #10094 * Changelog: add #10096 * Testing list: add more information based on #10087 * Changelog: add #9847 * Changelog: add #10084 * Changelog: add #9918 * Changelog: add #7614 * Changelog: add #10116 * Changelog: add #10108 * Changelog: add #10041 * Changelog: add #10121 * Changelog: add #10134 * Changelog: add #10130 * Changelog: add #10109 * changelog: add #10137 * changelog: add #9952 * changelog: add #10120 * changelog: add #10162 * Changelog: add #10163 * Changelog: add #10092 * changelog: add #10156 * Changelog: add #10154 * changelog: add #10122 * Changelog: add #10101 * changelog: add #10105 * changelog: add #10190 * Changelog: add #10196 * changelog: add #10152 * Changelog: add #10153 * Testing list: add more details to Site Verification testing steps. @see #10143 (comment) * changelog: add #10194 * Changelog: add #10193
This PR changes attachment update syncing to be triggered by
attachment_updated
, and syncs a specific action when the update changes the post_parent from 0 to non-zero, which is indicative of an attachment being attached to a post.Testing Instructions:
Attach an existing post from your media library to a post by clicking
Add Media
in the post. You should see thejetpack_sync_save_update_attachment
sync action come through on your wpcom sandbox.phpunit tests were added to test this functionality as well