CronAccessCheck.php 869 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains Drupal\system\Access\CronAccessCheck.
 */

namespace Drupal\system\Access;

10
use Drupal\Core\Routing\Access\AccessInterface;
11 12 13 14

/**
 * Access check for cron routes.
 */
15
class CronAccessCheck implements AccessInterface {
16 17

  /**
18 19 20 21 22 23 24
   * Checks access.
   *
   * @param string $key
   *   The cron key.
   *
   * @return string
   *   A \Drupal\Core\Access\AccessInterface constant value.
25
   */
26
  public function access($key) {
27
    if ($key != \Drupal::state()->get('system.cron_key')) {
28
      \Drupal::logger('cron')->notice('Cron could not run because an invalid key was used.');
29
      return static::KILL;
30
    }
31
    elseif (\Drupal::state()->get('system.maintenance_mode')) {
32
      \Drupal::logger('cron')->notice('Cron could not run because the site is in maintenance mode.');
33
      return static::KILL;
34
    }
35
    return static::ALLOW;
36 37
  }
}