wp-cli.php 1.6 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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
 * Prepare environment
 */
if ( ! \Automattic\WP\Cron_Control\Events_Store::is_installed() ) {
	// 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' ) ) {
		return;
	}

	// Create table and die, to ensure command runs with proper state
	\Automattic\WP\Cron_Control\Events_Store::instance()->cli_create_tables();

	\WP_CLI::error( __( 'Cron Control installation completed. Please try again.', 'automattic-cron-control' ) );
}

Erick Hitter's avatar
Erick Hitter committed
30
31
32
33
34
/**
 * Consistent time format across commands
 */
const TIME_FORMAT = 'Y-m-d H:i:s';

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 *  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
 */
59
60
require __DIR__ . '/wp-cli/class-cache.php';
require __DIR__ . '/wp-cli/class-events.php';
61
require __DIR__ . '/wp-cli/class-lock.php';
62
require __DIR__ . '/wp-cli/class-one-time-fixers.php';
63
require __DIR__ . '/wp-cli/class-orchestrate.php';
64
require __DIR__ . '/wp-cli/class-rest-api.php';