Tribe__Events__Aggregator__Record__Abstract::is_schedule_time()
Verifies if this Schedule Record can create a new Child Record
Return
(boolean)
Source
File: src/Tribe/Aggregator/Record/Abstract.php
public function is_schedule_time() {
if ( tribe_is_truthy( getenv( 'TRIBE_DEBUG_OVERRIDE_SCHEDULE' ) ) ) {
return true;
}
// If we are not on a Schedule Type
if ( ! $this->is_schedule ) {
return false;
}
// If we are not dealing with the Record Schedule
if ( $this->post->post_status !== Tribe__Events__Aggregator__Records::$status->schedule ) {
return false;
}
// In some cases the scheduled import may be inactive and should not run during cron
if ( false === $this->frequency ) {
return false;
}
// It's never time for On Demand schedule, bail!
if ( ! isset( $this->frequency->id ) || 'on_demand' === $this->frequency->id ) {
return false;
}
$retry_interval = $this->get_retry_interval();
$failure_time_threshold = time() - $retry_interval;
// If the last import status is an error and it happened before half the frequency ago let's try again
if (
(
$this->has_own_last_import_status()
&& $this->failed_before( $failure_time_threshold )
)
|| $this->last_child()->failed_before( $failure_time_threshold )
) {
return true;
}
$current = time();
$last = strtotime( $this->post->post_modified_gmt );
$next = $last + $this->frequency->interval;
// let's add some randomization of -5 to 0 minutes (this makes sure we don't push a schedule beyond when it should fire off)
$next += ( mt_rand( -5, 0 ) * 60 );
// Only do anything if we have one of these metas
if ( ! empty( $this->meta['schedule_day'] ) || ! empty( $this->meta['schedule_time'] ) ) {
// Setup to avoid notices
$maybe_next = 0;
// Now depending on the type of frequency we build the
switch ( $this->frequency->id ) {
case 'daily':
$time_string = date( 'Y-m-d' ) . ' ' . $this->meta['schedule_time'];
$maybe_next = strtotime( $time_string );
break;
case 'weekly':
$start_week = date( 'Y-m-d', strtotime( '-' . date( 'w' ) . ' days' ) );
$scheduled_day = date( 'Y-m-d', strtotime( $start_week . ' +' . ( (int) $this->meta['schedule_day'] - 1 ) . ' days' ) );
$time_string = date( 'Y-m-d', strtotime( $scheduled_day ) ) . ' ' . $this->meta['schedule_time'];
$maybe_next = strtotime( $time_string );
break;
case 'monthly':
$time_string = date( 'Y-m-' ) . $this->meta['schedule_day'] . ' ' . $this->meta['schedule_time'];
$maybe_next = strtotime( $time_string );
break;
}
// If our Next date based on Last run is bigger than the scheduled time it means we bail
if ( $maybe_next > $next ) {
$next = $maybe_next;
}
}
return $current > $next;
}