Skip to content

Commit 3ed78e7

Browse files
committed
Merge branch 'main' into copilot/add-network-flag-event-run
2 parents 09f4ab1 + 8460962 commit 3ed78e7

File tree

6 files changed

+419
-29
lines changed

6 files changed

+419
-29
lines changed

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/.actrc export-ignore
2+
/.distignore export-ignore
3+
/.editorconfig export-ignore
4+
/.github export-ignore
5+
/.gitignore export-ignore
6+
/.typos.toml export-ignore
7+
/AGENTS.md export-ignore
8+
/behat.yml export-ignore
9+
/features export-ignore
10+
/phpcs.xml.dist export-ignore
11+
/phpstan.neon.dist export-ignore
12+
/phpunit.xml.dist export-ignore
13+
/tests export-ignore
14+
/wp-cli.yml export-ignore

.github/workflows/copilot-setup-steps.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ jobs:
2121

2222
- name: Check existence of composer.json file
2323
id: check_composer_file
24-
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
25-
with:
26-
files: "composer.json"
24+
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
2725

2826
- name: Set up PHP environment
2927
if: steps.check_composer_file.outputs.files_exists == 'true'
30-
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
28+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
3129
with:
3230
php-version: 'latest'
3331
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -38,7 +36,7 @@ jobs:
3836

3937
- name: Install Composer dependencies & cache dependencies
4038
if: steps.check_composer_file.outputs.files_exists == 'true'
41-
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3
39+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v3
4240
env:
4341
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4442
with:

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ wp cron event
8888
Deletes all scheduled cron events for the given hook.
8989

9090
~~~
91-
wp cron event delete [<hook>...] [--due-now] [--exclude=<hooks>] [--all]
91+
wp cron event delete [<hook>...] [--due-now] [--exclude=<hooks>] [--all] [--match-args=<args>]
9292
~~~
9393

9494
**OPTIONS**
@@ -105,12 +105,19 @@ wp cron event delete [<hook>...] [--due-now] [--exclude=<hooks>] [--all]
105105
[--all]
106106
Delete all hooks.
107107

108+
[--match-args=<args>]
109+
Only delete events whose arguments match the given JSON-encoded array or scalar value. Argument types must match exactly (for example, `["123"]` vs `[123]`). Requires exactly one hook name.
110+
108111
**EXAMPLES**
109112

110113
# Delete all scheduled cron events for the given hook
111114
$ wp cron event delete cron_test
112115
Success: Deleted a total of 2 cron events.
113116

117+
# Delete a specific cron event by hook and arguments
118+
$ wp cron event delete cron_test --match-args='["123"]'
119+
Success: Deleted a total of 1 cron event.
120+
114121

115122

116123
### wp cron event list
@@ -160,6 +167,7 @@ These fields are optionally available:
160167
* schedule
161168
* interval
162169
* next_run
170+
* actions
163171

164172
**EXAMPLES**
165173

@@ -193,7 +201,8 @@ wp cron event run [<hook>...] [--due-now] [--exclude=<hooks>] [--all]
193201
One or more hooks to run.
194202

195203
[--due-now]
196-
Run all hooks due right now.
204+
Run all hooks due right now. Respects the doing_cron transient to
205+
prevent overlapping runs.
197206

198207
[--exclude=<hooks>]
199208
Comma-separated list of hooks to exclude.

features/cron-event.feature

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,77 @@ Feature: Manage WP Cron events
198198
Success: Executed a total of 2 cron events across 3 sites.
199199
"""
200200

201+
Scenario: List cron events with actions field
202+
Given a wp-content/mu-plugins/test-cron-actions.php file:
203+
"""
204+
<?php
205+
add_action( 'wp_cli_test_hook', 'wp_cli_test_function' );
206+
add_action( 'wp_cli_test_hook', array( 'MyTestClass', 'my_method' ) );
207+
add_action( 'wp_cli_test_hook_closure', function() {
208+
// Test closure
209+
} );
210+
211+
function wp_cli_test_function() {
212+
// Test function
213+
}
214+
215+
class MyTestClass {
216+
public static function my_method() {
217+
// Test method
218+
}
219+
}
220+
"""
221+
222+
When I run `wp cron event schedule wp_cli_test_hook now`
223+
Then STDOUT should contain:
224+
"""
225+
Success: Scheduled event with hook 'wp_cli_test_hook'
226+
"""
227+
228+
When I run `wp cron event list --fields=hook,actions --format=csv`
229+
Then STDOUT should contain:
230+
"""
231+
wp_cli_test_function
232+
"""
233+
And STDOUT should contain:
234+
"""
235+
MyTestClass::my_method
236+
"""
237+
238+
When I run `wp cron event list --hook=wp_cli_test_hook --fields=hook,actions --format=json`
239+
Then STDOUT should be JSON containing:
240+
"""
241+
[{"hook":"wp_cli_test_hook"}]
242+
"""
243+
And STDOUT should contain:
244+
"""
245+
wp_cli_test_function
246+
"""
247+
248+
When I run `wp cron event schedule wp_cli_test_hook_closure now`
249+
Then STDOUT should contain:
250+
"""
251+
Success: Scheduled event with hook 'wp_cli_test_hook_closure'
252+
"""
253+
254+
When I run `wp cron event list --hook=wp_cli_test_hook_closure --fields=hook,actions --format=csv`
255+
Then STDOUT should contain:
256+
"""
257+
Closure
258+
"""
259+
260+
When I run `wp cron event schedule wp_cli_test_hook_no_actions now`
261+
Then STDOUT should contain:
262+
"""
263+
Success: Scheduled event with hook 'wp_cli_test_hook_no_actions'
264+
"""
265+
266+
When I run `wp cron event list --hook=wp_cli_test_hook_no_actions --fields=hook,actions --format=csv`
267+
Then STDOUT should contain:
268+
"""
269+
None
270+
"""
271+
201272
Scenario: Confirm that cron event run in debug mode shows the start of events
202273
When I try `wp cron event run wp_version_check --debug=cron`
203274
Then STDOUT should contain:
@@ -212,3 +283,31 @@ Feature: Manage WP Cron events
212283
"""
213284
Debug: Beginning execution of cron event 'wp_version_check'
214285
"""
286+
287+
Scenario: --due-now respects the doing_cron transient and skips when another run is in progress
288+
When I run `wp cron event schedule wp_cli_test_event_lock now hourly`
289+
Then STDOUT should contain:
290+
"""
291+
Success: Scheduled event with hook 'wp_cli_test_event_lock'
292+
"""
293+
294+
# Simulate an in-progress cron run by setting the doing_cron transient.
295+
When I run `wp eval 'set_transient( "doing_cron", sprintf( "%.22F", microtime( true ) ) );'`
296+
297+
And I try `wp cron event run --due-now`
298+
Then STDERR should contain:
299+
"""
300+
Warning: A cron event run is already in progress; skipping.
301+
"""
302+
And STDOUT should not contain:
303+
"""
304+
wp_cli_test_event_lock
305+
"""
306+
307+
# After the transient is cleared, the run should proceed normally.
308+
When I run `wp eval 'delete_transient( "doing_cron" );'`
309+
And I try `wp cron event run --due-now`
310+
Then STDOUT should contain:
311+
"""
312+
Executed the cron event 'wp_cli_test_event_lock'
313+
"""

features/cron.feature

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,13 @@ Feature: Manage WP-Cron events and schedules
307307
# executes the "wp_privacy_delete_old_export_files" event there.
308308
@require-wp-5.0
309309
Scenario: Run currently scheduled events
310+
# Disable web-triggered cron so spawn_cron() cannot set doing_cron between
311+
# steps - wp cron event run always defines DOING_CRON so this has no effect
312+
# on the commands being tested.
313+
When I run `wp config set DISABLE_WP_CRON true --raw`
314+
310315
# WP throws a notice here for older versions of core.
311-
When I try `wp cron event run --all`
316+
And I try `wp cron event run --all`
312317
Then STDOUT should contain:
313318
"""
314319
Executed the cron event 'wp_version_check'
@@ -583,3 +588,68 @@ Feature: Manage WP-Cron events and schedules
583588
"""
584589
Error: Please either specify cron events, or use --all.
585590
"""
591+
592+
Scenario: Delete a specific cron event by matching args
593+
When I run `wp cron event schedule wp_cli_test_event_5 '+20 minutes' --0=banana`
594+
And I run `wp cron event schedule wp_cli_test_event_5 '+20 minutes' --0=bar`
595+
Then STDOUT should not be empty
596+
597+
When I run `wp cron event list --format=csv --fields=hook,recurrence,args`
598+
Then STDOUT should be CSV containing:
599+
| hook | recurrence | args |
600+
| wp_cli_test_event_5 | Non-repeating | ["banana"] |
601+
| wp_cli_test_event_5 | Non-repeating | ["bar"] |
602+
603+
When I run `wp cron event delete wp_cli_test_event_5 --match-args='["banana"]'`
604+
Then STDOUT should be:
605+
"""
606+
Success: Deleted a total of 1 cron event.
607+
"""
608+
609+
When I run `wp cron event list --format=csv --fields=hook,args`
610+
Then STDOUT should be CSV containing:
611+
| hook | args |
612+
| wp_cli_test_event_5 | ["bar"] |
613+
And STDOUT should not contain:
614+
"""
615+
["banana"]
616+
"""
617+
618+
When I run `wp cron event delete wp_cli_test_event_5 --match-args=bar`
619+
Then STDOUT should be:
620+
"""
621+
Success: Deleted a total of 1 cron event.
622+
"""
623+
624+
When I try `wp cron event list`
625+
Then STDOUT should not contain:
626+
"""
627+
wp_cli_test_event_5
628+
"""
629+
630+
When I run `wp cron event schedule wp_cli_test_event_5 '+20 minutes' --0=banana`
631+
Then STDOUT should not be empty
632+
633+
When I try `wp cron event delete wp_cli_test_event_5 --match-args='["banana"]' --all`
634+
Then STDERR should be:
635+
"""
636+
Error: The --match-args parameter cannot be combined with --all or --due-now.
637+
"""
638+
639+
When I try `wp cron event delete wp_cli_test_event_5 --match-args='["banana"]' --due-now`
640+
Then STDERR should be:
641+
"""
642+
Error: The --match-args parameter cannot be combined with --all or --due-now.
643+
"""
644+
645+
When I try `wp cron event delete --match-args='["banana"]'`
646+
Then STDERR should be:
647+
"""
648+
Error: The --match-args parameter requires exactly one hook name.
649+
"""
650+
651+
When I try `wp cron event delete wp_cli_test_event_5 wp_cli_test_event_5 --match-args='["banana"]'`
652+
Then STDERR should be:
653+
"""
654+
Error: The --match-args parameter requires exactly one hook name.
655+
"""

0 commit comments

Comments
 (0)