You are here

function automatic_updates_cron in Automatic Updates 8.2

Same name and namespace in other branches
  1. 8 automatic_updates.module \automatic_updates_cron()
  2. 7 automatic_updates.module \automatic_updates_cron()

Implements hook_cron().

1 string reference to 'automatic_updates_cron'
CronUpdaterTest::testUpdaterCalled in tests/src/Kernel/CronUpdaterTest.php
Tests that the cron handler calls the updater as expected.

File

./automatic_updates.module, line 28
Contains hook implementations for Automatic Updates.

Code

function automatic_updates_cron() {

  /** @var \Drupal\automatic_updates\CronUpdater $cron_updater */
  $cron_updater = \Drupal::classResolver(CronUpdater::class);
  $cron_updater
    ->handleCron();

  /** @var \Drupal\automatic_updates\Validation\ReadinessValidationManager $checker_manager */
  $checker_manager = \Drupal::service('automatic_updates.readiness_validation_manager');
  $last_results = $checker_manager
    ->getResults();
  $last_run_time = $checker_manager
    ->getLastRunTime();

  // Do not run readiness checks more than once an hour unless there are no
  // results available.
  if ($last_results === NULL || !$last_run_time || \Drupal::time()
    ->getRequestTime() - $last_run_time > 3600) {
    $checker_manager
      ->run();
  }
}