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

[wpmlbridge-301] Unsync documents on non indexable stati. #50

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$indexablePostStati = $postIndexable->get_indexable_post_status();
$indexablePostStatus = $postIndexable->get_indexable_post_status();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is also Stati in the commit so I don't know if it's a typo or intentional :)

everything else is great 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand stati is the plural form of status (as opposed to statuses which doesn't really exist). I saw it here:

https://developer.wordpress.org/reference/functions/get_post_stati/

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

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

}
Loading