Commit 6cb07946 authored by Erick Hitter's avatar Erick Hitter
Browse files

Set `DOING_CRON` as early as possible

parent a77ad897
......@@ -9,23 +9,32 @@ if ( ! defined( '\WP_CLI' ) || ! \WP_CLI ) {
/**
* Prepare environment
*/
if ( ! \Automattic\WP\Cron_Control\Events_Store::is_installed() ) {
function prepare_environment() {
// Only interfere with `cron-control` commands
$cmd = \WP_CLI::get_runner()->arguments;
if ( ! is_array( $cmd ) || ! isset( $cmd['0'] ) ) {
return;
}
$cmd = $cmd[0];
if ( false === strpos( $cmd, 'cron-control' ) ) {
if ( false === strpos( $cmd[0], 'cron-control' ) ) {
return;
}
// Create table and die, to ensure command runs with proper state
\Automattic\WP\Cron_Control\Events_Store::instance()->cli_create_tables();
if ( ! \Automattic\WP\Cron_Control\Events_Store::is_installed() ) {
\Automattic\WP\Cron_Control\Events_Store::instance()->cli_create_tables();
\WP_CLI::error( __( 'Cron Control installation completed. Please try again.', 'automattic-cron-control' ) );
\WP_CLI::error( __( 'Cron Control installation completed. Please try again.', 'automattic-cron-control' ) );
}
// Set DOING_CRON when appropriate
if ( isset( $cmd[1] ) && 'orchestrate' === $cmd[1] ) {
if ( ! defined( 'DOING_CRON' ) ) {
define( 'DOING_CRON', true );
}
}
}
prepare_environment();
/**
* Consistent time format across commands
......
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