-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scheduled updates pause feature (#37110)
* Initial changes * Add new unit tests * changelog * Updated version * Update versions * Fix: typo * Fix: typo.
- Loading branch information
Showing
13 changed files
with
428 additions
and
26 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/scheduled-updates/changelog/add-scheduled-update-pause
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add scheduled updates active flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
projects/packages/scheduled-updates/src/class-scheduled-updates-active.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/** | ||
* Scheduled Updates Active class | ||
* | ||
* @package automattic/scheduled-updates | ||
*/ | ||
|
||
namespace Automattic\Jetpack; | ||
|
||
/** | ||
* Scheduled_Updates_Active class | ||
* | ||
* This class provides static methods to get/save active for scheduled updates. | ||
*/ | ||
class Scheduled_Updates_Active { | ||
|
||
/** | ||
* The name of the WordPress option where the active option is stored. | ||
*/ | ||
const OPTION_NAME = 'jetpack_scheduled_update_active'; | ||
|
||
/** | ||
* Get the active value for a scheduled update. | ||
* | ||
* @param string $schedule_id Request ID. | ||
* @return bool Active value. | ||
*/ | ||
public static function get( $schedule_id ) { | ||
$option = get_option( self::OPTION_NAME, array() ); | ||
|
||
return $option[ $schedule_id ] ?? true; | ||
} | ||
|
||
/** | ||
* Update the active value for a scheduled update. | ||
* | ||
* @param string $schedule_id Request ID. | ||
* @param bool $active Active value. | ||
* @return bool | ||
*/ | ||
public static function update( $schedule_id, $active ) { | ||
$option = get_option( self::OPTION_NAME, array() ); | ||
|
||
if ( ! is_array( $option ) ) { | ||
$option = array(); | ||
} | ||
|
||
$option[ $schedule_id ] = $active; | ||
|
||
return update_option( self::OPTION_NAME, $option ); | ||
} | ||
|
||
/** | ||
* Clear the active value for a scheduled update. | ||
* | ||
* @param string|null $schedule_id Request ID. | ||
* @return bool | ||
*/ | ||
public static function clear( $schedule_id ) { | ||
$option = get_option( self::OPTION_NAME, array() ); | ||
|
||
if ( isset( $option[ $schedule_id ] ) ) { | ||
unset( $option[ $schedule_id ] ); | ||
} | ||
|
||
if ( count( $option ) ) { | ||
return update_option( self::OPTION_NAME, $option ); | ||
} else { | ||
return delete_option( self::OPTION_NAME ); | ||
} | ||
} | ||
|
||
/** | ||
* Update the active value 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_active( $id, $event, $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
$schedule = $request['schedule']; | ||
$active = $schedule['active'] ?? true; | ||
|
||
return self::update( $id, $active ); | ||
} | ||
|
||
/** | ||
* REST prepare_item_for_response filter. | ||
* | ||
* @param array $item WP Cron event. | ||
* @param \WP_REST_Request $request Request object. | ||
* @return array Response array on success. | ||
*/ | ||
public static function response_filter( $item, $request ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
$item['active'] = self::get( $item['schedule_id'] ); | ||
|
||
return $item; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.