Cron-Control
Cron-Control copied to clipboard
Add CLI command and function to delete events by schedule
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.
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.
@nickdaugherty Unit test failing:
- 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.
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();
This is really stale - going to close. We can revisit in the future if needed.