Skip to content

Commit

Permalink
fix 10up#2275
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinrue committed Aug 1, 2021
1 parent 4707033 commit 62da34a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
28 changes: 0 additions & 28 deletions includes/classes/Indexable/Post/SyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public function setup() {
add_action( 'add_attachment', array( $this, 'action_sync_on_update' ), 999, 3 );
add_action( 'edit_attachment', array( $this, 'action_sync_on_update' ), 999, 3 );
add_action( 'delete_post', array( $this, 'action_delete_post' ) );
add_action( 'delete_blog', array( $this, 'action_delete_blog_from_index' ) );
add_action( 'make_delete_blog', array( $this, 'action_delete_blog_from_index' ) );
add_action( 'make_spam_blog', array( $this, 'action_delete_blog_from_index' ) );
add_action( 'archive_blog', array( $this, 'action_delete_blog_from_index' ) );
add_action( 'deactivate_blog', array( $this, 'action_delete_blog_from_index' ) );
add_action( 'updated_post_meta', array( $this, 'action_queue_meta_sync' ), 10, 4 );
add_action( 'added_post_meta', array( $this, 'action_queue_meta_sync' ), 10, 4 );
add_action( 'deleted_post_meta', array( $this, 'action_queue_meta_sync' ), 10, 4 );
Expand Down Expand Up @@ -154,29 +149,6 @@ public function action_queue_meta_sync( $meta_id, $object_id, $meta_key, $meta_v
}
}

/**
* Remove blog from index when a site is deleted, archived, or deactivated
*
* @param int $blog_id WP Blog ID.
*/
public function action_delete_blog_from_index( $blog_id ) {
if ( $this->kill_sync() ) {
return;
}

$indexable = Indexables::factory()->get( $this->indexable_slug );

/**
* Filter to whether to keep index on site deletion
*
* @hook ep_keep_index
* @param {bool} $keep True means don't delete index
* @return {boolean} New value
*/
if ( $indexable->index_exists( $blog_id ) && ! apply_filters( 'ep_keep_index', false ) ) {
$indexable->delete_index( $blog_id );
}
}

/**
* Delete ES post when WP post is deleted
Expand Down
38 changes: 38 additions & 0 deletions includes/classes/SyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public function __construct( $indexable_slug ) {
add_action( 'shutdown', [ $this, 'index_sync_queue' ] );
add_filter( 'wp_redirect', [ $this, 'index_sync_queue_on_redirect' ], 10, 1 );

/**
* Actions for multisite
*/
add_action( 'delete_blog', array( $this, 'action_delete_blog_from_index' ) );
add_action( 'make_delete_blog', array( $this, 'action_delete_blog_from_index' ) );
add_action( 'make_spam_blog', array( $this, 'action_delete_blog_from_index' ) );
add_action( 'archive_blog', array( $this, 'action_delete_blog_from_index' ) );
add_action( 'deactivate_blog', array( $this, 'action_delete_blog_from_index' ) );

// Implemented by children.
$this->setup();
}
Expand Down Expand Up @@ -223,6 +232,35 @@ public function kill_sync() {
return apply_filters( 'ep_sync_indexable_kill', $is_importing, $this->indexable_slug );
}

/**
* Remove blog from index when a site is deleted, archived, or deactivated
*
* @param int $blog_id WP Blog ID.
*/
public function action_delete_blog_from_index( $blog_id ) {
if ( $this->kill_sync() ) {
return;
}

$indexable = Indexables::factory()->get( $this->indexable_slug );

// Don't delete global indexes
if ( $indexable->global ) {
return;
}

/**
* Filter to whether to keep index on site deletion
*
* @hook ep_keep_index
* @param {bool} $keep True means don't delete index
* @return {boolean} New value
*/
if ( $indexable->index_exists( $blog_id ) && ! apply_filters( 'ep_keep_index', false ) ) {
$indexable->delete_index( $blog_id );
}
}

/**
* Implementation should setup hooks/filters
*
Expand Down

0 comments on commit 62da34a

Please sign in to comment.