You are here

class CronFrequency in Automatic Updates 8

Cron frequency checker.

Hierarchy

Expanded class hierarchy of CronFrequency

1 string reference to 'CronFrequency'
automatic_updates.services.yml in ./automatic_updates.services.yml
automatic_updates.services.yml
1 service uses CronFrequency
automatic_updates.cron_frequency in ./automatic_updates.services.yml
Drupal\automatic_updates\ReadinessChecker\CronFrequency

File

src/ReadinessChecker/CronFrequency.php, line 13

Namespace

Drupal\automatic_updates\ReadinessChecker
View source
class CronFrequency implements ReadinessCheckerInterface {
  use StringTranslationTrait;

  /**
   * Minimum cron threshold is 3 hours.
   */
  const MINIMUM_CRON_INTERVAL = 10800;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * CronFrequency constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The state service.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) {
    $this->configFactory = $config_factory;
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public function run() {
    $messages = [];
    if ($this->moduleHandler
      ->moduleExists('automated_cron') && $this->configFactory
      ->get('automated_cron.settings')
      ->get('interval') > $this::MINIMUM_CRON_INTERVAL) {
      $messages[] = $this
        ->t('Cron is not set to run frequently enough. <a href="@configure">Configure it</a> to run at least every 3 hours or disable automated cron and run it via an external scheduling system.', [
        '@configure' => Url::fromRoute('system.cron_settings')
          ->toString(),
      ]);
    }
    return $messages;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CronFrequency::$configFactory protected property The config factory.
CronFrequency::$moduleHandler protected property The module handler.
CronFrequency::MINIMUM_CRON_INTERVAL constant Minimum cron threshold is 3 hours.
CronFrequency::run public function Run check. Overrides ReadinessCheckerInterface::run
CronFrequency::__construct public function CronFrequency constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.