Skip to content

Delete multiple events at once - #81

Closed
Mike-Hermans wants to merge 7338 commits into
wp-cli:masterfrom
Mike-Hermans:39-add-all-flag-to-delete
Closed

Mike-Hermans wants to merge 7338 commits into
wp-cli:masterfrom
Mike-Hermans:39-add-all-flag-to-delete

Conversation

@Mike-Hermans

@Mike-Hermans Mike-Hermans commented Jun 2, 2022 •

Copy link
Copy Markdown
Contributor

Fixes #39 by making the command more consistent with the wp cron event run command.

It is now possible to delete multiple cron events at once by either:

  • Specifying multiple hooks that need to be deleted:
$ wp cron event delete wp_version_check wp_update_plugins
  • Delete all cron events that are due now
$ wp cron event delete --due-now
  • Delete all cron events at once
$ wp cron event delete --all

Since the selection process of the run and delete command is now the same, a separate function has been added to filter the required hooks (::get_selected_cron_events()).

danielbachhuber and others added 30 commits February 7, 2017 11:19
General improvements to the build process
Escape prefix when listing all tables with prefix
Display correct error when plugin update fails to update plugins
```
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing symfony/finder (v2.8.16)
  - Installing symfony/finder (v2.8.17)
    Loading from cache

  - Removing symfony/yaml (v2.8.16)
  - Installing symfony/yaml (v2.8.17)
    Downloading: 100%

  - Removing symfony/filesystem (v2.8.16)
  - Installing symfony/filesystem (v2.8.17)
    Loading from cache

  - Removing symfony/config (v2.8.16)
  - Installing symfony/config (v2.8.17)
    Downloading: 100%

  - Removing symfony/debug (v2.8.16)
  - Installing symfony/debug (v2.8.17)
    Downloading: 100%

  - Removing symfony/console (v2.8.16)
  - Installing symfony/console (v2.8.17)
    Downloading: 100%

  - Removing symfony/dependency-injection (v2.8.16)
  - Installing symfony/dependency-injection (v2.8.17)
    Downloading: 100%

  - Removing symfony/event-dispatcher (v2.8.16)
  - Installing symfony/event-dispatcher (v2.8.17)
    Loading from cache

  - Removing symfony/process (v2.8.16)
  - Installing symfony/process (v2.8.17)
    Downloading: 100%

  - Removing symfony/translation (v2.8.16)
  - Installing symfony/translation (v2.8.17)
    Downloading: 100%

  - Removing wp-cli/php-cli-tools (v0.11.1)
  - Installing wp-cli/php-cli-tools (v0.11.2)
    Downloading: 100%

Writing lock file
Generating autoload files
```
Update Composer dependencies (2/15/2017)
Remove XDebug from PHP runtime within Travis CI environment.
Cache Composer in scaffolded plugin `.travis.yml`
Issues 3817 Existing PDF previews not deleted on media regenerate.
By default, disable auto-commit and (unique and forefin) key checks.
Introduce skip-optimization flag to force old behavior.
@Mike-Hermans Mike-Hermans changed the title Delete multiple events Delete multiple events at once Jun 2, 2022

@janw-me janw-me left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the refactor.
The tests need a bit more work.

Comment thread features/cron.feature Resolved
Comment thread README.md Resolved
Comment thread features/cron.feature Resolved
@danielbachhuber

Copy link
Copy Markdown
Member

@Mike-Hermans @janw-me How's this pull request coming along? Anything I can help with?

@Mike-Hermans

Copy link
Copy Markdown
Contributor Author

Hi @danielbachhuber

I was waiting on a response from @janw-me on the cron.feature test from the conversation above, and a new review based on the changes made.

@janw-me

janw-me commented Aug 11, 2022

Copy link
Copy Markdown
Member

Sorry, I didn't see the notification.
The last comment was just to check.
@Mike-Hermans his conformation was all we need.

Comment thread src/Cron_Event_Command.php Outdated
Comment on lines +438 to +440
if ( empty( $args ) && ! Utils\get_flag_value( $assoc_args, 'due-now' ) && ! Utils\get_flag_value( $assoc_args, 'all' ) ) {
WP_CLI::error( 'Please specify one or more cron events, or use --due-now/--all.' );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This also needs safeguards for flag combinations that don't make sense.

  • If you provide hooks, the addition of --due-now or --all should throw an error.
  • Providing both --due-now and --all at the same time should throw an error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note: these should also have there seperate test cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. I will fix this soon.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @schlessera

After seeing other tests break I realized it should be possible to select hooks and combine them with the --due-now parameter. Only hooks + --all and --due-now --all should be invalid.

Comment thread src/Cron_Event_Command.php Resolved
Comment thread src/Cron_Event_Command.php Resolved
@danielbachhuber danielbachhuber added command:cron Related to 'cron' command command:cron-event-delete Related to 'cron event delete' command labels Aug 11, 2022
@Mike-Hermans

Copy link
Copy Markdown
Contributor Author

Hi @schlessera

I've updated the code and tests. Hooks are now valid in combination with --due-now, as this was already possible on the 'run' command as well.

@danielbachhuber

Copy link
Copy Markdown
Member

Proceeding with wp-cli/wp-cli#5594 for this repository. I've captured this PR to https://gist.github.com/danielbachhuber/09504e7a7cdb1144c2e6162950d2f594 in case this PR is auto-closed or broken in some way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:cron Related to 'cron' command command:cron-event-delete Related to 'cron event delete' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion, add a --all flag to wp cron delete