Cron-Control icon indicating copy to clipboard operation
Cron-Control copied to clipboard

Add CLI command and function to delete events by schedule

Open nickdaugherty opened this issue 7 years ago • 3 comments
trafficstars

Sometimes it's useful to remove all events that have a given schedule.

Specifically, we want to use this to clean out all one-time events when syncing a database between a production and pre-production environment on VIP Go.

nickdaugherty avatar Feb 01 '18 00:02 nickdaugherty

Two passing thoughts:

  • dealing with #102 and inverting that work to handle deletes may be more-widely applicable, as I can't recall needing to delete by schedule in any other scenario, but deleting by action has come up before;
  • this could use an internal-cache clear after the delete runs, which should probably be a separate issue as existing commands need this change too.

ethitter avatar Feb 01 '18 02:02 ethitter

@nickdaugherty Unit test failing:

  1. Automattic\WP\Cron_Control\Tests\Events_Store_Tests::test_delete_events_by_schedule Unexpected incorrect usage notice for wpdb::prepare Failed asserting that an array is empty.

GaryJones avatar Mar 03 '20 23:03 GaryJones

Specifically, we want to use this to clean out all one-time events when syncing a database between a production and pre-production environment on VIP Go.

This is a good goal I think, as I imagine for the most part you don't need want them (like a syndicate_post_id type event that was registered when a post was published on production). But there may also be cases where it could bite you, like a plugin/core update registering a one-time migrate_old_data_type type thing. Bit of a catch-22.

If we do add this, maybe we don't need it to be a top-level CLI. W/ the incoming changes to the plugin (and a few adjustments), we could do the cleanup inside our existing "data sync cleanup" cli w/ logic that looks something like this:

$events = Events::query( [ 'schedule' => false ] );
foreach ( $events as $event ) {
  $event->delete();
}

// Or a more performant (single SQL statement), but less flexible, api:
Events::instance()->delete_non_recurring_events();

WPprodigy avatar Dec 17 '21 19:12 WPprodigy

This is really stale - going to close. We can revisit in the future if needed.

nickdaugherty avatar Sep 20 '22 15:09 nickdaugherty