Skip to content
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

Merged
merged 8 commits into from
Sep 6, 2018

Conversation

gititon
Copy link
Contributor

@gititon gititon commented Sep 4, 2018

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 the jetpack_sync_save_update_attachment sync action come through on your wpcom sandbox.

phpunit tests were added to test this functionality as well

@gititon gititon added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Package] Sync labels Sep 4, 2018
@gititon gititon requested a review from a team as a code owner September 4, 2018 21:04
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D17928-code. (newly created revision)

@jetpackbot
Copy link
Collaborator

Warnings
⚠️

"Testing instructions" are missing for this PR. Please add some

⚠️

"Proposed changelog entry" is missing for this PR. Please include any meaningful changes

This is automated check which relies on PULL_REQUEST_TEMPLATE.We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS

@@ -9,8 +9,10 @@ public function init_listeners( $callable ) {
add_action( 'edit_attachment', array( $this, 'send_attachment_info' ) );
Copy link
Member

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.

jeherve
jeherve previously requested changes Sep 5, 2018
Copy link
Member

@jeherve jeherve left a 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
Copy link
Member

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!

Copy link
Member

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!

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D17928-code. (updated diff)

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D17928-code. (updated diff)

$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 );
Copy link
Member

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.

Copy link
Member

@roccotripaldi roccotripaldi left a 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 );
Copy link
Member

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

@gititon
Copy link
Contributor Author

gititon commented Sep 5, 2018

@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' );

Copy link
Member

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 ) {
Copy link
Member

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?

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D17928-code. (updated diff)

Copy link
Member

@enejb enejb left a 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.

@gititon gititon deleted the sync-attachment-attached branch September 6, 2018 19:20
@jeherve jeherve added [Status] Has Changelog and removed [Status] Needs Changelog [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Sep 14, 2018
jeherve added a commit that referenced this pull request Sep 14, 2018
jeherve added a commit that referenced this pull request Sep 24, 2018
jeherve added a commit that referenced this pull request Sep 25, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants