Skip to content

Commit

Permalink
Remove sync option backward-compatibility temporary solution (#37132)
Browse files Browse the repository at this point in the history
* Remove sync option backward-compatibility

* changelog
  • Loading branch information
zaerl authored May 8, 2024
1 parent a494171 commit 9a852ea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: removed

Remove sync option backward-compatibility temporary solution
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ public static function init() {
// Active flag saving.
add_action( 'add_option_' . Scheduled_Updates_Active::OPTION_NAME, $callback );
add_action( 'update_option_' . Scheduled_Updates_Active::OPTION_NAME, $callback );

// This is a temporary solution for backward compatibility. It will be removed in the future.
// It's needed to ensure that preexisting schedules are loaded into the sync option.
if ( false === get_option( self::PLUGIN_CRON_HOOK ) ) {
call_user_func( $callback );
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function set_up() {
Scheduled_Updates::init();

self::$sync_counter = 0;
add_action( 'add_option', array( __CLASS__, 'sync_callback' ) );
add_action( 'update_option', array( __CLASS__, 'sync_callback' ) );
}

Expand All @@ -79,6 +80,7 @@ public function tear_down() {
remove_filter( 'jetpack_scheduled_update_verify_plugins', '__return_true', 11 );

self::$sync_counter = 0;
remove_action( 'add_option', array( __CLASS__, 'sync_callback' ) );
remove_action( 'update_option', array( __CLASS__, 'sync_callback' ) );
}

Expand Down Expand Up @@ -267,40 +269,6 @@ public function test_create_multiple_item() {
$this->assertSame( 2, self::$sync_counter );
}

/**
* Temporary test to ensure backward compatibility. It will be removed in the future.
*/
public function test_init_backward_compatibility() {
$plugins = array(
'custom-plugin/custom-plugin.php',
'gutenberg/gutenberg.php',
);
$request = new WP_REST_Request( 'POST', '/wpcom/v2/update-schedules' );
$request->set_body_params(
array(
'plugins' => $plugins,
'schedule' => $this->get_schedule(),
)
);

wp_set_current_user( $this->admin_id );
$result = rest_do_request( $request );

$this->assertSame( 200, $result->get_status() );

$pre_sync_option = get_option( Scheduled_Updates::PLUGIN_CRON_HOOK );
$this->assertIsArray( $pre_sync_option );

// Force deleting the option to test backward compatibility.
$this->assertTrue( delete_option( Scheduled_Updates::PLUGIN_CRON_HOOK ) );

// Simulate an init.
Scheduled_Updates::init();
$post_sync_option = get_option( Scheduled_Updates::PLUGIN_CRON_HOOK );
$this->assertEquals( $pre_sync_option, $post_sync_option );
$this->assertSame( 1, self::$sync_counter );
}

/**
* Can't have multiple schedules for the same time.
*
Expand Down

0 comments on commit 9a852ea

Please sign in to comment.