diff --git a/projects/packages/scheduled-updates/changelog/add-scheduled-updates-sync-3 b/projects/packages/scheduled-updates/changelog/add-scheduled-updates-sync-3 new file mode 100644 index 0000000000000..49abe27cf3968 --- /dev/null +++ b/projects/packages/scheduled-updates/changelog/add-scheduled-updates-sync-3 @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Populated sync option with results from endpoint. diff --git a/projects/packages/scheduled-updates/src/class-scheduled-updates.php b/projects/packages/scheduled-updates/src/class-scheduled-updates.php index cfa2c27a20a00..ab0488a29ed91 100644 --- a/projects/packages/scheduled-updates/src/class-scheduled-updates.php +++ b/projects/packages/scheduled-updates/src/class-scheduled-updates.php @@ -158,25 +158,18 @@ public static function delete_scheduled_update( $timestamp, $plugins ) { * Save the schedules for sync after cron option saving. */ public static function update_option_cron() { - $events = wp_get_scheduled_events( self::PLUGIN_CRON_HOOK ); - - foreach ( array_keys( $events ) as $schedule_id ) { - $events[ $schedule_id ]->schedule_id = $schedule_id; - - $status = self::get_scheduled_update_status( $schedule_id ); + $endpoint = new \WPCOM_REST_API_V2_Endpoint_Update_Schedules(); + $events = $endpoint->get_items( new \WP_REST_Request() ); - if ( ! $status ) { - $status = array( - 'last_run_timestamp' => null, - 'last_run_status' => null, - ); - } - - $events[ $schedule_id ]->last_run_timestamp = $status['last_run_timestamp']; - $events[ $schedule_id ]->last_run_status = $status['last_run_status']; + if ( ! is_wp_error( $events ) ) { + $option = array_map( + function ( $event ) { + return (object) $event; + }, + $events->get_data() + ); + update_option( self::PLUGIN_CRON_HOOK, $option ); } - - update_option( self::PLUGIN_CRON_HOOK, $events ); } /**