Skip to content

Commit

Permalink
Populate sync option with results from endpoint (#36915)
Browse files Browse the repository at this point in the history
* Populate sync option with results from endpoint

* changelog
  • Loading branch information
zaerl authored Apr 17, 2024
1 parent da623ba commit d63547d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Populated sync option with results from endpoint.
27 changes: 10 additions & 17 deletions projects/packages/scheduled-updates/src/class-scheduled-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down

0 comments on commit d63547d

Please sign in to comment.