Skip to content

Commit

Permalink
Update/dont sync set object terms action for blacklisted taxonomies (#…
Browse files Browse the repository at this point in the history
…41597)

* Don't send term relationships for full sync posts actions since they are not being processed

* changelog

* Fixed next-version typo

* Remove test no longer valid

* changelog
  • Loading branch information
darssen authored Feb 7, 2025
1 parent 0831a42 commit 60e22d6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: deprecated

Sync: Full sync for posts not sending term relationships
23 changes: 22 additions & 1 deletion projects/packages/sync/src/modules/class-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function init_before_send() {
// Full sync.
$sync_module = Modules::get_module( 'full-sync' );
if ( $sync_module instanceof Full_Sync_Immediately ) {
add_filter( 'jetpack_sync_before_send_jetpack_full_sync_posts', array( $this, 'add_term_relationships' ) );
add_filter( 'jetpack_sync_before_send_jetpack_full_sync_posts', array( $this, 'build_full_sync_action_array' ) );
} else {
add_filter( 'jetpack_sync_before_send_jetpack_full_sync_posts', array( $this, 'expand_posts_with_metadata_and_terms' ) );
}
Expand Down Expand Up @@ -779,6 +779,25 @@ public function send_published( $post_ID, $post ) {
}
}

/**
* Build the full sync action object for Posts.
*
* @access public
*
* @param array $args An array with the posts and the previous end.
*
* @return array An array with the posts, postmeta and the previous end.
*/
public function build_full_sync_action_array( $args ) {
list( $filtered_posts, $previous_end ) = $args;
return array(
$filtered_posts['objects'],
$filtered_posts['meta'],
array(), // WPCOM does not process term relationships in full sync posts actions for a while now, let's skip them.
$previous_end,
);
}

/**
* Add term relationships to post objects within a hook before they are serialized and sent to the server.
* This is used in Full Sync Immediately
Expand All @@ -787,8 +806,10 @@ public function send_published( $post_ID, $post ) {
*
* @param array $args The hook parameters.
* @return array $args The expanded hook parameters.
* @deprecated since $$next-version$$
*/
public function add_term_relationships( $args ) {
_deprecated_function( __METHOD__, '$$next-version$$' );
list( $filtered_posts, $previous_interval_end ) = $args;

return array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function get_objects_by_id( $object_type, $ids ) {
* @deprecated since $$next-version$$
*/
public function expand_order_objects( $args ) {
_deprecated_function( __METHOD__, 'next-version' );
_deprecated_function( __METHOD__, '$$next-version$$' );
list( $order_ids, $previous_end ) = $args;
return array(
'orders' => $this->get_objects_by_id( 'order', $order_ids ),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Sync: Full sync for posts not sending term relationships
Original file line number Diff line number Diff line change
Expand Up @@ -679,24 +679,6 @@ public function test_full_sync_doesnt_sends_forbiden_private_or_public_post_meta
$this->assertEquals( 'foo5', $this->server_replica_storage->get_metadata( 'post', $post_id, 'a_public_meta', true ) );
}

public function test_full_sync_sends_all_post_terms() {
$post_id = self::factory()->post->create();
wp_set_object_terms( $post_id, 'tag', 'post_tag' );

$this->sender->do_sync();
$terms = get_the_terms( $post_id, 'post_tag' );

$this->assertEqualsObject( $terms, $this->server_replica_storage->get_the_terms( $post_id, 'post_tag' ), 'Initial sync doesn\'t work' );
// reset the storage, check value, and do full sync - storage should be set!
$this->server_replica_storage->reset();

$this->assertFalse( $this->server_replica_storage->get_the_terms( $post_id, 'post_tag' ), 'Not empty' );
$this->full_sync->start();
$this->sender->do_full_sync();

$this->assertEqualsObject( $terms, $this->server_replica_storage->get_the_terms( $post_id, 'post_tag' ), 'Full sync doesn\'t work' );
}

public function test_full_sync_sends_all_comment_meta() {
$post_id = self::factory()->post->create();
$comment_ids = self::factory()->comment->create_post_comments( $post_id );
Expand Down

0 comments on commit 60e22d6

Please sign in to comment.