Skip to content

Commit

Permalink
[wpmlbridge-301] Unsync documents on non indexable stati.
Browse files Browse the repository at this point in the history
- Unsync documents with a status not supported by their indexes.

#49
  • Loading branch information
decodekult committed Jul 10, 2024
1 parent 80b50b1 commit 1a8bb75
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/Sync/Singular.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ function( $hook ) {
add_action( $hook, [ $this, 'completeUnsync' ], Constants::LATE_HOOK_PRIORITY );
}
);

add_action( 'transition_post_status', [ $this, 'maybeUnsyncByStatus' ], Constants::LATE_HOOK_PRIORITY, 3 );
}

/**
Expand All @@ -105,7 +107,7 @@ private function getIdsInSyncQueue( $syncManager ) {
* @return bool
*/
public function manageSyncQueue( $halt, $syncManager, $indexableSlug ) {
if ( \WPML\ElasticPress\Constants::INDEXABLE_SLUG_POST !== $indexableSlug ) {
if ( Constants::INDEXABLE_SLUG_POST !== $indexableSlug ) {
return $halt;
}

Expand Down Expand Up @@ -234,4 +236,29 @@ public function clearIndexLanguageByMeta( $metaId, $postId ) {
$this->clearIndexLanguage( $postId );
}

/**
* @param string $newStatus
* @param string $oldStatus
* @param \WP_Post $post
*/
public function maybeUnsyncByStatus( $newStatus, $oldStatus, $post ) {
if ( $oldStatus === $newStatus ) {
return;
}

$postIndexable = $this->indexables->get( Constants::INDEXABLE_SLUG_POST );
if ( false === $postIndexable ) {
return;
}

$indexablePostStati = $postIndexable->get_indexable_post_status();
if ( in_array( $post->post_status, $indexablePostStati, true ) ) {
return;
}

$this->startUnsync( $post->ID );
$this->clearIndexLanguage( $post->ID );
$this->completeUnsync( $post->ID );
}

}

0 comments on commit 1a8bb75

Please sign in to comment.