You are here

function _automatic_updates_checker_requirements in Automatic Updates 7

Same name and namespace in other branches
  1. 8 automatic_updates.install \_automatic_updates_checker_requirements()

Display requirements from results of readiness checker.

Parameters

array $requirements: The requirements array.

1 call to _automatic_updates_checker_requirements()
automatic_updates_requirements in ./automatic_updates.install
Implements hook_requirements().

File

./automatic_updates.install, line 50
Install, update and uninstall functions for the automatic_updates module.

Code

function _automatic_updates_checker_requirements(array &$requirements) {
  if (!ReadinessCheckerManager::isEnabled()) {
    return;
  }
  $last_check_timestamp = ReadinessCheckerManager::timestamp();
  $requirements['automatic_updates_readiness'] = [
    'title' => t('Update readiness checks'),
    'severity' => REQUIREMENT_OK,
    'value' => t('Your site is ready to for <a href="@readiness_checks">automatic updates</a>.', [
      '@readiness_checks' => 'https://www.drupal.org/docs/7/update/automatic-updates#readiness-checks',
    ]),
  ];
  $error_results = ReadinessCheckerManager::getResults('error');
  $warning_results = ReadinessCheckerManager::getResults('warning');
  $checker_results = array_merge($error_results, $warning_results);
  if (!empty($checker_results)) {
    $requirements['automatic_updates_readiness']['severity'] = $error_results ? REQUIREMENT_ERROR : REQUIREMENT_WARNING;
    $requirements['automatic_updates_readiness']['value'] = format_plural(count($checker_results), '@count check failed:', '@count checks failed:');
    $requirements['automatic_updates_readiness']['description'] = theme('item_list', array(
      'items' => $checker_results,
    ));
  }
  if (REQUEST_TIME > $last_check_timestamp + 3600 * 24) {
    $requirements['automatic_updates_readiness']['severity'] = REQUIREMENT_ERROR;
    $requirements['automatic_updates_readiness']['value'] = t('Your site has not recently checked if it is ready to apply <a href="@readiness_checks">automatic updates</a>.', [
      '@readiness_checks' => 'https://www.drupal.org/docs/7/update/automatic-updates#readiness-checks',
    ]);
    $time_ago = format_interval(REQUEST_TIME - $last_check_timestamp);
    if ($last_check_timestamp === 0) {
      $requirements['automatic_updates_readiness']['description'] = t('<a href="@link">Run readiness checks</a> manually.', [
        '@link' => url('admin/config/system/automatic_updates/readiness'),
      ]);
    }
    else {
      $requirements['automatic_updates_readiness']['description'] = t('Last run @time ago. <a href="@link">Run readiness checks</a> manually.', [
        '@time' => $time_ago,
        '@link' => url('admin/config/system/automatic_updates/readiness'),
      ]);
    }
  }
}