Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As apart of #234, this will help cleanup duplicate events that exist (daily). It's pretty safe, as we only look at recurring events that have the exact same action/args/schedule. There is really no need to have events like that. If you need the same hook on the same schedule, then the args need to be different to make them unique. If the args don't matter though, then probably the event should be looked into being added onto a schedule that occurs more often.
This alone won't solve all our problems mentioned in that issue, but no matter what we're going to need to cleanup the messes that currently exist. So this seems like a good starting point. Notably, this should drastically help reduce the "duplicate entry" db errors that can cause events to become stuck at the top of the queue and repeatedly run each cycle.
I opted for not including duplicate single events, since they technically clean themselves up. But could possibly revisit that in the future. For those will probably want to respect the "10minute window" that core checks: https://developer.wordpress.org/reference/functions/wp_schedule_single_event/. As in, only remove duplicate single events that exist within 10minutes of each other.
Testing
The unit test is pretty good for this as well :)
Did fresh WP install w/ cron control disabled and ran the following:
Then activated cron control, and refreshed twice so the table & internal events could be setup. Then ran cron (so the cleanup legacy data task runs). Afterwards, both
custom_single_event
were in the custom table and only onecustom_recurring_event
was left.