Skip to content
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
21 changes: 15 additions & 6 deletions php/sync/class-sync-queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function is_enabled() {
*/
public function load_hooks() {
add_action( 'cloudinary_resume_queue', array( $this, 'maybe_resume_queue' ) );
add_action( 'settings_save_setting_auto_sync', array( $this, 'change_setting_state' ), 10, 3 );
add_action( 'cloudinary_settings_save_setting_auto_sync', array( $this, 'change_setting_state' ), 10, 3 );
}

/**
Expand All @@ -188,9 +188,14 @@ public function load_hooks() {
* @return mixed
*/
public function change_setting_state( $new_value, $current_value, $setting ) {
if ( $this->is_running() && 'on' === $current_value && 'off' === $new_value ) {
$this->shutdown_queue();
$setting->add_error_notice( 'disabled_sync', 'Bulk sync has been disabled.', 'warning' );
// shutdown queues if needed.
if ( 'on' === $current_value && 'off' === $new_value ) {
if ( $this->is_running() ) {
$this->shutdown_queue( 'queue' );
$setting->add_error_notice( 'disabled_sync', 'Bulk sync has been disabled.', 'warning' );
Copy link
Contributor

Choose a reason for hiding this comment

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

@DavidCramer

I'm noticing here a problem, as add_error_notice() doesn't exist. Also, this message is missing i18n.

}
// Shutdown autosync queue.
$this->shutdown_queue( 'autosync' );
}

return $new_value;
Expand Down Expand Up @@ -268,7 +273,7 @@ public function get_post( $thread ) {
*/
public function is_running( $type = 'queue' ) {
if ( 'autosync' === $type ) {
return $this->sync->is_auto_sync_enabled();
return true; // Autosync always runs, however if off, auto sync queue building is off.
}
$queue = $this->get_queue();

Expand Down Expand Up @@ -356,6 +361,9 @@ public function stop_maybe( $type = 'queue' ) {
protected function shutdown_queue( $type = 'queue' ) {
if ( 'queue' === $type ) {
delete_option( self::$queue_enabled );
} elseif ( 'autosync' === $type ) {
// Remove pending flag.
delete_post_meta_by_key( Sync::META_KEYS['pending'] );
}
$this->stop_queue( $type );
}
Expand Down Expand Up @@ -535,7 +543,8 @@ protected function get_thread_queue_details( $thread ) {
'posts_per_page' => 1,
'fields' => 'ids',
'cache_results' => false,
'meta_query' => array( // phpcs:ignore
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'meta_query' => array(
array(
'key' => $thread,
'compare' => 'EXISTS',
Expand Down