You are here

public function AutomatedCron::onTerminate in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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\PostResponseEvent $event: The Event to process.

File

core/modules/automated_cron/src/EventSubscriber/AutomatedCron.php, line 65
Contains \Drupal\automated_cron\EventSubscriber\AutomatedCron.

Class

AutomatedCron
A subscriber running cron after a response is sent.

Namespace

Drupal\automated_cron\EventSubscriber

Code

public function onTerminate(PostResponseEvent $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();
    }
  }
}