[wp-trac] [WordPress Trac] #44818: cron: preventing duplicate events fails when the first event is too far in the past
WordPress Trac
noreply at wordpress.org
Mon Sep 3 07:18:23 UTC 2018
#44818: cron: preventing duplicate events fails when the first event is too far in
the past
-----------------------------+------------------------------
Reporter: bodohugobarwich | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Cron API | Version: 4.9.8
Severity: normal | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Comment (by peterwilsoncc):
Unfortunately such a check would reverse the problem rather than fix the
bug. If multiple events are scheduled, a new event could be registered
within ten minutes of all but the last event.
An accurate check would require looping through the cron array and
comparing any events that fall within ten minutes of the event being
scheduled. Something along the lines of:
{{{#!php
<?php
foreach ( $crons as $timestamp => $cron ) {
if ( /* the two timestamps are greater than ten minutes apart */ )
{
continue;
}
if ( isset( $cron[ $hook ][ $key ] ) ) {
// Prevent scheduling.
return false;
}
}
}}}
`array_filter()` can't be used to reduce the array as the `$flag`
parameter is missing from older versions of PHP.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44818#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list