You are here

public function AutomatedCron::onTerminate in Drupal 9

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\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();
    }
  }
}