WordPress.org

Make WordPress Core

Ticket #28213: wp_schedule_single_event-r28372.patch

File wp_schedule_single_event-r28372.patch, 2.1 KB (added by tellyworth, 7 years ago)
  • src/wp-includes/cron.php

     
    2020 * @param array $args Optional. Arguments to pass to the hook's callback function.
    2121 */
    2222function wp_schedule_single_event( $timestamp, $hook, $args = array()) {
    23         // don't schedule a duplicate if there's already an identical event due in the next 10 minutes
     23        // don't schedule a duplicate if there's already an identical event due within 10 minutes of it
    2424        $next = wp_next_scheduled($hook, $args);
    25         if ( $next && $next <= $timestamp + 10 * MINUTE_IN_SECONDS )
     25        if ( $next && abs( $next - $timestamp) <= 10 * MINUTE_IN_SECONDS )
    2626                return;
    2727
    2828        $crons = _get_cron_array();
  • tests/phpunit/tests/cron.php

     
    223223                // second works too
    224224                wp_schedule_single_event( $ts2, $hook, $args );
    225225
    226                 // the next event should be at +5 minutes, not +3
     226                // the next event should be at +3 minutes, even though that one was scheduled second
    227227                $this->assertEquals( $ts2, wp_next_scheduled($hook, $args) );
    228228                wp_unschedule_event( $ts2, $hook, $args );
    229                 // following event should be there too
     229                // following event at +30 minutes should be there too
    230230                $this->assertEquals( $ts1, wp_next_scheduled($hook, $args) );
    231231        }
     232
     233        function test_not_duplicate_event_reversed() {
     234                // duplicate events far apart should work normally regardless of order
     235                $hook = rand_str();
     236                $args = array(rand_str());
     237                $ts1 = strtotime('+3 minutes');
     238                $ts2 = strtotime('+30 minutes');
     239
     240                // first one works
     241                wp_schedule_single_event( $ts1, $hook, $args );
     242                // second works too
     243                wp_schedule_single_event( $ts2, $hook, $args );
     244
     245                // the next event should be at +3 minutes
     246                $this->assertEquals( $ts1, wp_next_scheduled($hook, $args) );
     247                wp_unschedule_event( $ts1, $hook, $args );
     248                // following event should be there too
     249                $this->assertEquals( $ts2, wp_next_scheduled($hook, $args) );
     250        }
    232251}
    233252
    234253/*