From 9a852eab76ac37d08cb64ff9597facd1c1b8bf01 Mon Sep 17 00:00:00 2001 From: Francesco Bigiarini Date: Wed, 8 May 2024 18:13:10 +0200 Subject: [PATCH] Remove sync option backward-compatibility temporary solution (#37132) * Remove sync option backward-compatibility * changelog --- .../changelog/fix-remove-temp-backward-code | 4 +++ .../src/class-scheduled-updates.php | 6 ---- ...-api-v2-endpoint-update-schedules-test.php | 36 ++----------------- 3 files changed, 6 insertions(+), 40 deletions(-) create mode 100644 projects/packages/scheduled-updates/changelog/fix-remove-temp-backward-code diff --git a/projects/packages/scheduled-updates/changelog/fix-remove-temp-backward-code b/projects/packages/scheduled-updates/changelog/fix-remove-temp-backward-code new file mode 100644 index 0000000000000..b441963c9f581 --- /dev/null +++ b/projects/packages/scheduled-updates/changelog/fix-remove-temp-backward-code @@ -0,0 +1,4 @@ +Significance: patch +Type: removed + +Remove sync option backward-compatibility temporary solution diff --git a/projects/packages/scheduled-updates/src/class-scheduled-updates.php b/projects/packages/scheduled-updates/src/class-scheduled-updates.php index 83ce14faf5c07..a39d4fff93898 100644 --- a/projects/packages/scheduled-updates/src/class-scheduled-updates.php +++ b/projects/packages/scheduled-updates/src/class-scheduled-updates.php @@ -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 ); - } } /** diff --git a/projects/packages/scheduled-updates/tests/php/class-wpcom-rest-api-v2-endpoint-update-schedules-test.php b/projects/packages/scheduled-updates/tests/php/class-wpcom-rest-api-v2-endpoint-update-schedules-test.php index 8faf99ea6d0db..fcdaf2388a304 100644 --- a/projects/packages/scheduled-updates/tests/php/class-wpcom-rest-api-v2-endpoint-update-schedules-test.php +++ b/projects/packages/scheduled-updates/tests/php/class-wpcom-rest-api-v2-endpoint-update-schedules-test.php @@ -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' ) ); } @@ -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' ) ); } @@ -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. *