Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
}
],
"require": {
"wp-cli/wp-cli": "^2.12"
"wp-cli/wp-cli": "^2.13"
},
"require-dev": {
"wp-cli/entity-command": "^1.3 || ^2",
"wp-cli/eval-command": "^2.0",
"wp-cli/server-command": "^2.0",
"wp-cli/wp-cli-tests": "^4"
"wp-cli/wp-cli-tests": "^5"
},
"config": {
"process-timeout": 7200,
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"johnpbloch/wordpress-core-installer": true
"johnpbloch/wordpress-core-installer": true,
"phpstan/extension-installer": true
},
"lock": false
},
Expand Down Expand Up @@ -62,12 +63,14 @@
"behat-rerun": "rerun-behat-tests",
"lint": "run-linter-tests",
"phpcs": "run-phpcs-tests",
"phpstan": "run-phpstan-tests",
"phpcbf": "run-phpcbf-cleanup",
"phpunit": "run-php-unit-tests",
"prepare-tests": "install-package-tests",
"test": [
"@lint",
"@phpcs",
"@phpstan",
"@phpunit",
"@behat"
]
Expand Down
8 changes: 0 additions & 8 deletions features/cron-event.feature
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ Feature: Manage WP Cron events
Error: No events found for hook 'wp_cli_test_event'.
"""

@less-than-wp-4.9.0
Scenario: Unschedule cron event for WP < 4.9.0, wp_unschedule_hook was not included
When I try `wp cron event unschedule wp_cli_test_event_1`
Then STDERR should be:
"""
Error: Unscheduling events is only supported from WordPress 4.9.0 onwards.
"""

Scenario: Run cron event with a registered shutdown function
Given a wp-content/mu-plugins/setup_shutdown_function.php file:
"""
Expand Down
14 changes: 14 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
level: 9
paths:
- src
- cron-command.php
scanDirectories:
- vendor/wp-cli/wp-cli/php
scanFiles:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
treatPhpDocTypesAsCertain: false
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.parameter
- identifier: missingType.return
3 changes: 1 addition & 2 deletions src/Cron_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function test() {
*/
protected static function get_cron_spawn() {

$sslverify = \WP_CLI\Utils\wp_version_compare( 4.0, '<' );
$doing_wp_cron = sprintf( '%.22F', microtime( true ) );

$cron_request_array = array(
Expand All @@ -75,7 +74,7 @@ protected static function get_cron_spawn() {
'timeout' => 3,
'blocking' => true,
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling native WordPress hook.
'sslverify' => apply_filters( 'https_local_ssl_verify', $sslverify ),
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
),
);

Expand Down
28 changes: 22 additions & 6 deletions src/Cron_Event_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@
* @package wp-cli
*/
class Cron_Event_Command extends WP_CLI_Command {

/**
* @var string[]
*/
private $fields = array(
'hook',
'next_run_gmt',
'next_run_relative',
'recurrence',
);

/**
* @var string
*/
private static $time_format = 'Y-m-d H:i:s';

/**
Expand Down Expand Up @@ -154,13 +159,17 @@ public function list_( $args, $assoc_args ) {
* # Schedule new cron event and pass arguments
* $ wp cron event schedule cron_test '+1 hour' --0=first-argument --1=second-argument
* Success: Scheduled event with hook 'cron_test' for 2016-05-31 11:21:35 GMT.
*
* @param array{0: string, 1?: string, 2?: string} $args Positional arguments.
* @param array<int, string> $assoc_args Associative arguments.
*/
public function schedule( $args, $assoc_args ) {
if ( count( $assoc_args ) && count( array_filter( array_keys( $assoc_args ), 'is_string' ) ) ) {
WP_CLI::warning( 'Numeric keys should be used for the hook arguments.' );
}

$hook = $args[0];
$hook = $args[0];

$next_run = Utils\get_flag_value( $args, 1, 'now' );
$recurrence = Utils\get_flag_value( $args, 2, false );

Expand Down Expand Up @@ -263,10 +272,6 @@ public function unschedule( $args, $assoc_args ) {

list( $hook ) = $args;

if ( Utils\wp_version_compare( '4.9.0', '<' ) ) {
WP_CLI::error( 'Unscheduling events is only supported from WordPress 4.9.0 onwards.' );
}

$unscheduled = wp_unschedule_hook( $hook );

if ( empty( $unscheduled ) ) {
Expand Down Expand Up @@ -457,6 +462,10 @@ protected static function get_cron_events( $is_due_now = false ) {
protected static function get_selected_cron_events( $args, $assoc_args ) {
$due_now = Utils\get_flag_value( $assoc_args, 'due-now' );
$all = Utils\get_flag_value( $assoc_args, 'all' );

/**
* @var string $exclude
*/
$exclude = Utils\get_flag_value( $assoc_args, 'exclude' );

if ( empty( $args ) && ! $due_now && ! $all ) {
Expand Down Expand Up @@ -549,11 +558,18 @@ private static function interval( $since ) {
array( 1, 'second' ),
);

$name = 'second';
$count = 0;
$seconds = 1;

// we only want to output two chunks of time here, eg:
// x years, xx months
// x days, xx hours
// so there's only two bits of calculation below:

$i = 0;
$j = 0;

// step one: the first chunk
for ( $i = 0, $j = count( $chunks ); $i < $j; $i++ ) {
$seconds = $chunks[ $i ][0];
Expand Down
4 changes: 3 additions & 1 deletion src/Cron_Schedule_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* +------------+-------------+----------+
*/
class Cron_Schedule_Command extends WP_CLI_Command {

/**
* @var string[]
*/
private $fields = array(
'name',
'display',
Expand Down