You are here

function automatic_updates_init in Automatic Updates 7

Implements hook_init().

File

./automatic_updates.module, line 11
Contains automatic_updates.module.

Code

function automatic_updates_init() {
  if (arg(0) == 'admin' && user_access('administer site configuration')) {
    $disabled_routes = array(
      'admin/appearance/update',
      'admin/appearance/install',
      'admin/modules/update',
      'admin/modules/install',
      'admin/reports/updates',
      'admin/reports/updates/update',
      'admin/reports/updates/install',
      'admin/reports/updates/settings',
      'admin/reports/status',
      'admin/update/ready',
    );

    // These paths don't need additional nagging.
    if (in_array($_GET['q'], $disabled_routes)) {
      return;
    }
    $messages = AutomaticUpdatesPsa::getPublicServiceMessages();
    if ($messages) {
      drupal_set_message(t('Public service announcements:'), 'error', FALSE);
      foreach ($messages as $message) {
        drupal_set_message($message, 'error', FALSE);
      }
    }
    $last_check_timestamp = ReadinessCheckerManager::timestamp();
    if (REQUEST_TIME > $last_check_timestamp + 3600 * 24) {
      drupal_set_message(t('Your site has not recently run an update readiness check. <a href="@link">Administer automatic updates</a> and run readiness checks manually.', [
        '@link' => url('admin/config/system/automatic_updates'),
      ]), 'error', FALSE);
    }
    $results = ReadinessCheckerManager::getResults('error');
    if ($results) {
      drupal_set_message(t('Your site is currently failing readiness checks for automatic updates. It cannot be <a href="@readiness_checks">automatically updated</a> until further action is performed:', [
        '@readiness_checks' => 'https://www.drupal.org/docs/7/update/automatic-updates#readiness-checks',
      ]), 'error', FALSE);
      foreach ($results as $message) {
        drupal_set_message($message, 'error', FALSE);
      }
    }
    $results = ReadinessCheckerManager::getResults('warning');
    if ($results) {
      drupal_set_message(t('Your site does not pass some readiness checks for automatic updates. Depending on the nature of the failures, it might effect the eligibility for <a href="@readiness_checks">automatic updates</a>.', [
        '@readiness_checks' => 'https://www.drupal.org/docs/7/update/automatic-updates#readiness-checks',
      ]), 'warning', FALSE);
      foreach ($results as $message) {
        drupal_set_message($message, 'warning', FALSE);
      }
    }
  }
}