Commit 3cc39c57 authored by Erick Hitter's avatar Erick Hitter
Browse files

Split status check and status changes, to reduce magic in the command

parent 1d136208
...@@ -7,54 +7,62 @@ namespace Automattic\WP\Cron_Control\CLI; ...@@ -7,54 +7,62 @@ namespace Automattic\WP\Cron_Control\CLI;
*/ */
class Orchestrate extends \WP_CLI_Command { class Orchestrate extends \WP_CLI_Command {
/** /**
* Check and change status of automatic event execution * Check the status of automatic event execution
*
* @subcommand check-status
*/
public function get_automatic_execution_status( $args, $assoc_args ) {
$status = get_option( \Automattic\WP\Cron_Control\Events::DISABLE_RUN_OPTION, 0 );
switch ( $status ) {
case 0 :
$status = __( 'Automatic execution is enabled', 'automattic-cron-control' );
break;
case 1 :
$status = __( 'Automatic execution is disabled indefinitely', 'automattic-cron-control' );
break;
default :
$status = sprintf( __( 'Automatic execution is disabled until %s', 'automattic-cron-control' ), date_i18n( 'Y-m-d H:i:s T', $status ) );
break;
}
\WP_CLI::log( $status );
}
/**
* Change status of automatic event execution
* *
* When using the Go-based runner, it may be necessary to stop execution for a period, or indefinitely * When using the Go-based runner, it may be necessary to stop execution for a period, or indefinitely
* *
* @subcommand manage-automatic-execution * @subcommand manage-automatic-execution
* @synopsis [--enable] [--disable] [--disable_until=<disable_until>] * @synopsis [--enable] [--disable] [--disable_until=<disable_until>]
*/ */
public function toggle_event_execution( $args, $assoc_args ) { public function manage_automatic_execution( $args, $assoc_args ) {
// Update execution status // Update execution status
$disable_ts = \WP_CLI\Utils\get_flag_value( $assoc_args, 'disable_until', 0 ); $disable_ts = \WP_CLI\Utils\get_flag_value( $assoc_args, 'disable_until', 0 );
$disable_ts = absint( $disable_ts ); $disable_ts = absint( $disable_ts );
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'enable', false ) ) { if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'enable', false ) ) {
update_option( \Automattic\WP\Cron_Control\Events::DISABLE_RUN_OPTION, 0 ); update_option( \Automattic\WP\Cron_Control\Events::DISABLE_RUN_OPTION, 0 );
\WP_CLI::success( 'Enabled' ); \WP_CLI::success( __( 'Enabled', 'automattic-cron-control' ) );
return; return;
} elseif ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'disable', false ) ) { } elseif ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'disable', false ) ) {
update_option( \Automattic\WP\Cron_Control\Events::DISABLE_RUN_OPTION, 1 ); update_option( \Automattic\WP\Cron_Control\Events::DISABLE_RUN_OPTION, 1 );
\WP_CLI::success( 'Disabled' ); \WP_CLI::success( __( 'Disabled', 'automattic-cron-control' ) );
return; return;
} elseif( $disable_ts > 0 ) { } elseif( $disable_ts > 0 ) {
if ( $disable_ts > time() ) { if ( $disable_ts > time() ) {
update_option( \Automattic\WP\Cron_Control\Events::DISABLE_RUN_OPTION, $disable_ts ); update_option( \Automattic\WP\Cron_Control\Events::DISABLE_RUN_OPTION, $disable_ts );
\WP_CLI::success( sprintf( 'Disabled until %s', date( 'Y-m-d H:i:s T', $disable_ts ) ) ); \WP_CLI::success( sprintf( __( 'Disabled until %s', 'automattic-cron-control' ), date_i18n( 'Y-m-d H:i:s T', $disable_ts ) ) );
return; return;
} else { } else {
\WP_CLI::error( 'Timestamp is in the past.' ); \WP_CLI::error( __( 'Timestamp is in the past.', 'automattic-cron-control' ) );
} }
} }
// Display existing status \WP_CLI::error( __( 'Please provide a valid action.', 'automattic-cron-control' ) );
$status = get_option( \Automattic\WP\Cron_Control\Events::DISABLE_RUN_OPTION, 0 );
switch ( $status ) {
case 0 :
$status = 'Automatic execution is enabled';
break;
case 1 :
$status = 'Automatic execution is disabled indefinitely';
break;
default :
$status = sprintf( 'Automatic execution is disabled until %s', date( 'Y-m-d H:i:s T', $status ) );
break;
}
\WP_CLI::log( $status );
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment