wp-cli.php 1.84 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
		\Automattic\WP\Cron_Control\set_doing_cron();
33
	}
34
}
35
prepare_environment();
36

Erick Hitter's avatar
Erick Hitter committed
37
38
39
40
41
/**
 * Consistent time format across commands
 */
const TIME_FORMAT = 'Y-m-d H:i:s';

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 *  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
 */
66
67
require __DIR__ . '/wp-cli/class-cache.php';
require __DIR__ . '/wp-cli/class-events.php';
68
require __DIR__ . '/wp-cli/class-lock.php';
69
require __DIR__ . '/wp-cli/class-one-time-fixers.php';
70
require __DIR__ . '/wp-cli/class-orchestrate.php';
71
require __DIR__ . '/wp-cli/class-orchestrate-runner.php';
72
require __DIR__ . '/wp-cli/class-rest-api.php';