You are here

function automatic_updates_cron in Automatic Updates 7

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

Implements hook_cron().

File

./automatic_updates.module, line 98
Contains automatic_updates.module.

Code

function automatic_updates_cron() {

  // Only allow cron to run once every hour.
  $cron_last_check = variable_get('automatic_updates.cron_last_check', 0);
  if (REQUEST_TIME - $cron_last_check < 3600) {
    return;
  }

  // Checkers should run before updates because of class caching.
  Notify::send();
  foreach (ReadinessCheckerManager::getCategories() as $category) {
    ReadinessCheckerManager::run($category);
  }

  // In-place updates won't function for dev releases of Drupal core.
  $dev_core = strpos(VERSION, '-dev') !== FALSE;
  if (!$dev_core && variable_get('automatic_updates_enable_cron_updates', FALSE)) {
    update_refresh();
    update_fetch_data();
    $available = update_get_available(TRUE);
    $projects = update_calculate_project_data($available);
    $not_recommended_version = $projects['drupal']['status'] !== UPDATE_CURRENT;
    $security_update = in_array($projects['drupal']['status'], [
      UPDATE_NOT_SECURE,
      UPDATE_REVOKED,
    ], TRUE);
    $recommended_release = isset($projects['drupal']['releases'][$projects['drupal']['recommended']]) ? $projects['drupal']['releases'][$projects['drupal']['recommended']] : NULL;

    // Don't update from/to same version.
    if ($not_recommended_version && $projects['drupal']['existing_version'] !== $recommended_release['version']) {
      if (variable_get('automatic_updates_enable_cron_security_updates', FALSE)) {
        if ($security_update) {
          InPlaceUpdate::update('drupal', 'core', VERSION, $recommended_release['version']);
        }
      }
      else {
        InPlaceUpdate::update('drupal', 'core', VERSION, $recommended_release['version']);
      }
    }
  }
  variable_set('automatic_updates.cron_last_check', time());
}