Skip to content

Commit

Permalink
Scheduled Updates: Move health check functions into hooks (#37067)
Browse files Browse the repository at this point in the history
* Move health check functions into hooks

* changelog

* Add a new hook to handle the update

* Fix version mismatch

* Update version

* Fix version

* Move updates_health_paths to Scheduled_Updates_Health_Paths class
  • Loading branch information
ouikhuan authored Apr 29, 2024
1 parent da79b1e commit 91efee8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Scheduled Updates: move health check functions into hooks
2 changes: 1 addition & 1 deletion projects/packages/scheduled-updates/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"autotagger": true,
"branch-alias": {
"dev-trunk": "0.9.x-dev"
"dev-trunk": "0.10.x-dev"
},
"textdomain": "jetpack-scheduled-updates",
"version-constants": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,18 @@ public static function validate( $path ) {

return $ret;
}

/**
* Update the health check paths for a scheduled update hook.
*
* @param string $id The ID of the schedule.
* @param object $event The event object.
* @param \WP_REST_Request $request The request object.
* @return bool
*/
public static function updates_health_paths( $id, $event, $request ) {
$schedule = $request['schedule'];
$paths = $schedule['health_check_paths'] ?? array();
return self::update( $id, $paths );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Scheduled_Updates {
*
* @var string
*/
const PACKAGE_VERSION = '0.9.1';
const PACKAGE_VERSION = '0.10.0-alpha';

/**
* The cron event hook for the scheduled plugins update.
Expand Down Expand Up @@ -61,6 +61,8 @@ public static function init() {
add_action( 'jetpack_scheduled_update_deleted', array( __CLASS__, 'enable_autoupdates' ), 10, 2 );
add_action( 'jetpack_scheduled_update_updated', array( Scheduled_Updates_Logs::class, 'replace_logs_schedule_id' ), 10, 2 );
add_action( 'jetpack_scheduled_update_deleted', array( Scheduled_Updates_Logs::class, 'delete_logs_schedule_id' ), 10, 3 );
add_action( 'jetpack_scheduled_update_created', array( Scheduled_Updates_Health_Paths::class, 'updates_health_paths' ), 10, 3 );
add_action( 'jetpack_scheduled_update_deleted', array( Scheduled_Updates_Health_Paths::class, 'clear' ) );

// Update cron sync option after options update.
$callback = array( __CLASS__, 'update_option_cron' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ public function create_item( $request ) {
}

$id = Scheduled_Updates::generate_schedule_id( $plugins );
Scheduled_Updates_Health_Paths::update( $id, $schedule['health_check_paths'] ?? array() );

/**
* Fires when a scheduled update is created.
Expand Down Expand Up @@ -504,8 +503,6 @@ public function delete_item( $request ) {
*/
do_action( 'jetpack_scheduled_update_deleted', $request['schedule_id'], $event, $request );

Scheduled_Updates_Health_Paths::clear( $request['schedule_id'] );

return rest_ensure_response( true );
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/mu-wpcom-plugin/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 91efee8

Please sign in to comment.