Skip to content

Commit

Permalink
Merge pull request #2621 from 10up/fix/multisite-sync-manager
Browse files Browse the repository at this point in the history
Fix/multisite sync manager
  • Loading branch information
oscarssanchez authored Mar 2, 2022
2 parents 3dfe277 + 7abbd64 commit aaf2a33
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
16 changes: 16 additions & 0 deletions includes/classes/Indexable/Comment/SyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ public function setup() {
add_action( 'updated_comment_meta', [ $this, 'action_queue_meta_sync' ], 10, 2 );
}

/**
* Un-setup actions and filters (for multisite).
*
* @since 4.0
*/
public function tear_down() {
remove_action( 'wp_insert_comment', [ $this, 'action_sync_on_insert' ] );
remove_action( 'edit_comment', [ $this, 'action_sync_on_update' ] );
remove_action( 'transition_comment_status', [ $this, 'action_sync_on_transition_comment_status' ] );
remove_action( 'trashed_comment', [ $this, 'action_sync_on_delete' ] );
remove_action( 'deleted_comment', [ $this, 'action_sync_on_delete' ] );
remove_action( 'added_comment_meta', [ $this, 'action_queue_meta_sync' ] );
remove_action( 'deleted_comment_meta', [ $this, 'action_queue_meta_sync' ] );
remove_action( 'updated_comment_meta', [ $this, 'action_queue_meta_sync' ] );
}

/**
* Sync ES index when new comments are saved
*
Expand Down
19 changes: 19 additions & 0 deletions includes/classes/Indexable/Post/SyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ public function setup() {
add_filter( 'ep_sync_delete_permissions_bypass', array( $this, 'filter_bypass_permission_checks_for_machines' ) );
}

/**
* Un-setup actions and filters (for multisite).
*
* @since 4.0
*/
public function tear_down() {
remove_action( 'wp_insert_post', array( $this, 'action_sync_on_update' ), 999 );
remove_action( 'add_attachment', array( $this, 'action_sync_on_update' ), 999 );
remove_action( 'edit_attachment', array( $this, 'action_sync_on_update' ), 999 );
remove_action( 'delete_post', array( $this, 'action_delete_post' ) );
remove_action( 'updated_post_meta', array( $this, 'action_queue_meta_sync' ) );
remove_action( 'added_post_meta', array( $this, 'action_queue_meta_sync' ) );
remove_filter( 'delete_post_metadata', array( $this, 'maybe_delete_meta_for_all' ) );
remove_action( 'deleted_post_meta', array( $this, 'action_queue_meta_sync' ) );
remove_action( 'wp_initialize_site', array( $this, 'action_create_blog_index' ) );
remove_filter( 'ep_sync_insert_permissions_bypass', array( $this, 'filter_bypass_permission_checks_for_machines' ) );
remove_filter( 'ep_sync_delete_permissions_bypass', array( $this, 'filter_bypass_permission_checks_for_machines' ) );
}

/**
* Whether to delete all meta from other posts that is associated with the deleted post.
*
Expand Down
16 changes: 16 additions & 0 deletions includes/classes/Indexable/Term/SyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ public function setup() {
add_action( 'set_object_terms', [ $this, 'action_sync_on_object_update' ], 10, 2 );
}

/**
* Un-setup actions and filters (for multisite).
*
* @since 4.0
*/
public function tear_down() {
remove_action( 'created_term', [ $this, 'action_sync_on_update' ] );
remove_action( 'edited_terms', [ $this, 'action_sync_on_update' ] );
remove_action( 'added_term_meta', [ $this, 'action_queue_meta_sync' ] );
remove_action( 'deleted_term_meta', [ $this, 'action_queue_meta_sync' ] );
remove_action( 'updated_term_meta', [ $this, 'action_queue_meta_sync' ] );
remove_action( 'pre_delete_term', [ $this, 'action_queue_children_sync' ] );
remove_action( 'pre_delete_term', [ $this, 'action_sync_on_delete' ] );
remove_action( 'set_object_terms', [ $this, 'action_sync_on_object_update' ] );
}

/**
* Sync ES index with changes to the term being saved
*
Expand Down
6 changes: 6 additions & 0 deletions includes/classes/Indexable/User/SyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public function setup() {
// @todo Handle deleted meta
}

/**
* Dummy implementation of site unsetup method (for now)
*/
public function tear_down() {
}

/**
* When whitelisted meta is updated/added/deleted, queue the object for reindex
*
Expand Down
12 changes: 10 additions & 2 deletions includes/classes/SyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ public function index_sync_queue() {
* @return boolean
*/
public function can_index_site() {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
return Utils\is_site_indexable();
if ( ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) && ! Utils\is_site_indexable() ) {
$this->tear_down();
return false;
}

return true;
Expand Down Expand Up @@ -272,4 +273,11 @@ public function action_delete_blog_from_index( $blog_id ) {
* @since 3.0
*/
abstract public function setup();

/**
* Implementation (for multisite) should un-setup hooks/filters if applicable.
*
* @since 4.0
*/
abstract public function tear_down();
}

0 comments on commit aaf2a33

Please sign in to comment.