function AutomatedCron::onTerminate

Same name in other branches
  1. 9 core/modules/automated_cron/src/EventSubscriber/AutomatedCron.php \Drupal\automated_cron\EventSubscriber\AutomatedCron::onTerminate()
  2. 8.9.x core/modules/automated_cron/src/EventSubscriber/AutomatedCron.php \Drupal\automated_cron\EventSubscriber\AutomatedCron::onTerminate()
  3. 11.x core/modules/automated_cron/src/EventSubscriber/AutomatedCron.php \Drupal\automated_cron\EventSubscriber\AutomatedCron::onTerminate()

Run the automated cron if enabled.

Parameters

\Symfony\Component\HttpKernel\Event\TerminateEvent $event: The Event to process.

File

core/modules/automated_cron/src/EventSubscriber/AutomatedCron.php, line 60

Class

AutomatedCron
A subscriber running cron after a response is sent.

Namespace

Drupal\automated_cron\EventSubscriber

Code

public function onTerminate(TerminateEvent $event) {
    $interval = $this->config
        ->get('interval');
    if ($interval > 0) {
        $cron_next = $this->state
            ->get('system.cron_last', 0) + $interval;
        if ((int) $event->getRequest()->server
            ->get('REQUEST_TIME') > $cron_next) {
            $this->cron
                ->run();
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.