Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to unschedule all events with a given hook #51

Merged

Conversation

vaishaliagola27
Copy link
Contributor

Adds unschedule command -

wp cron event unschedule <hook>

Fixes #48

@vaishaliagola27 vaishaliagola27 requested a review from a team as a code owner Nov 21, 2019
src/Cron_Event_Command.php Outdated Show resolved Hide resolved
features/cron-event.feature Show resolved Hide resolved
Copy link
Member

@thrijith thrijith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @vaishaliagola27

@schlessera Could you please do a final review?

Thanks

Copy link
Member

@schlessera schlessera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great, @vaishaliagola27 !

I have a few nitpicks regarding the language, mostly, to make it more consistent with the rest of WP-CLI.

Once we got these in shape, this is probably good for merging!

*/
public function unschedule( $args, $assoc_args ) {

$hook = $args[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a more recent convention, we've switched to using list() for fetching all required positional arguments. This looks strange with only a single one, but it's always good to just stick to the convention nevertheless.

Suggested change
$hook = $args[0];
list( $hook ) = $args;

sprintf(
'Unscheduled %1$d %2$s with hook \'%3$s\'.',
$unscheduled,
_n( 'event', 'events', $unscheduled ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the helper provided by WP-CLI, instead of the translation functions:

Suggested change
_n( 'event', 'events', $unscheduled ),
Utils::pluralize( 'event', $unscheduled ),

@@ -269,6 +269,53 @@ public function run( $args, $assoc_args ) {
WP_CLI::success( sprintf( $message, $executed ) );
}

/**
* Unchedules cron event on specific hook.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Unchedules cron event on specific hook.
* Unschedules all cron events for a given hook.

README.md Outdated

### wp cron event unschedule

Unchedules cron event on specific hook.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Unchedules cron event on specific hook.
Unschedules all cron events for a given hook.

README.md Outdated
**OPTIONS**

<hook>
The hook name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The hook name.
Name of the hook for which all events should be unscheduled.

And I try `wp cron event unschedule wp_cli_test_event_1`
Then STDOUT should contain:
"""
Success: Unscheduled 1 event with hook 'wp_cli_test_event_1'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Success: Unscheduled 1 event with hook 'wp_cli_test_event_1'.
Success: Unscheduled 1 event for hook 'wp_cli_test_event_1'.

And I try `wp cron event unschedule wp_cli_test_event_2`
Then STDOUT should contain:
"""
Success: Unscheduled 2 events with hook 'wp_cli_test_event_2'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Success: Unscheduled 2 events with hook 'wp_cli_test_event_2'.
Success: Unscheduled 2 events for hook 'wp_cli_test_event_2'.

When I try `wp cron event unschedule wp_cli_test_event`
Then STDERR should be:
"""
Error: No event found with hook 'wp_cli_test_event'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Error: No event found with hook 'wp_cli_test_event'.
Error: No events found for hook 'wp_cli_test_event'.

When I try `wp cron event unschedule wp_cli_test_event_1`
Then STDERR should be:
"""
Error: The 'wp_unschedule_hook' function was only introduced in WordPress 4.9.0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Error: The 'wp_unschedule_hook' function was only introduced in WordPress 4.9.0.
Error: Unscheduling events is only supported from WordPress 4.9.0 onwards.

$unscheduled = wp_unschedule_hook( $hook );

if ( empty( $unscheduled ) ) {
$message = 'Event not unscheduled.';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$message = 'Event not unscheduled.';
$message = "Failed to unschedule events for hook '%1\$s'.";

@vaishaliagola27
Copy link
Contributor Author

@schlessera
I've addressed all the feedbacks. Please take a look.

@schlessera
Copy link
Member

Thanks for the PR, @vaishaliagola27 ! 🎉

@schlessera schlessera added this to the 2.0.4 milestone Dec 17, 2019
@schlessera schlessera merged commit 184ce82 into wp-cli:master Dec 17, 2019
danielbachhuber pushed a commit that referenced this pull request Nov 18, 2022
Add command to unschedule all events with a given hook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command to unschedule all events with a given hook
3 participants