wp-cli.php 2.07 KB
Newer Older
1
2
<?php

3
namespace Automattic\WP\Cron_Control\CLI;
4

5
6
if ( ! defined( '\WP_CLI' ) || ! \WP_CLI ) {
	return;
7
}
8

9
10
11
/**
 * Prepare environment
 */
12
function prepare_environment() {
13
14
15
16
17
18
	// Only interfere with `cron-control` commands
	$cmd = \WP_CLI::get_runner()->arguments;
	if ( ! is_array( $cmd ) || ! isset( $cmd['0'] ) ) {
		return;
	}

19
	if ( false === strpos( $cmd[0], 'cron-control' ) ) {
20
21
22
23
		return;
	}

	// Create table and die, to ensure command runs with proper state
24
25
	if ( ! \Automattic\WP\Cron_Control\Events_Store::is_installed() ) {
		\Automattic\WP\Cron_Control\Events_Store::instance()->cli_create_tables();
26

27
28
29
30
31
		\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] ) {
32
		@ini_set( 'display_errors', '0' ); // @codingStandardsIgnoreLine - error output breaks JSON used by runner
33
		\Automattic\WP\Cron_Control\set_doing_cron();
34
	}
35
}
36
prepare_environment();
37

Erick Hitter's avatar
Erick Hitter committed
38
39
/**
 * Consistent time format across commands
40
41
 *
 * Defined here for backwards compatibility, as it was here before it was in the primary namespace
Erick Hitter's avatar
Erick Hitter committed
42
 */
43
const TIME_FORMAT = \Automattic\WP\Cron_Control\TIME_FORMAT;
Erick Hitter's avatar
Erick Hitter committed
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
 *  Clear all of the caches for memory management
 */
function stop_the_insanity() {
	global $wpdb, $wp_object_cache;

	$wpdb->queries = array(); // or define( 'WP_IMPORTING', true );

	if ( ! is_object( $wp_object_cache ) )
		return;

	$wp_object_cache->group_ops      = array();
	$wp_object_cache->stats          = array();
	$wp_object_cache->memcache_debug = array();
	$wp_object_cache->cache          = array();

	if ( is_callable( $wp_object_cache, '__remoteset' ) ) {
		$wp_object_cache->__remoteset(); // important
	}
}

/**
 * Load commands
 */
69
70
require __DIR__ . '/wp-cli/class-cache.php';
require __DIR__ . '/wp-cli/class-events.php';
71
require __DIR__ . '/wp-cli/class-lock.php';
72
require __DIR__ . '/wp-cli/class-one-time-fixers.php';
73
require __DIR__ . '/wp-cli/class-orchestrate.php';
74
require __DIR__ . '/wp-cli/class-orchestrate-runner.php';
75
require __DIR__ . '/wp-cli/class-rest-api.php';