You are here

function upgrade_status_calculate_project_data in Upgrade Status 7

Same name and namespace in other branches
  1. 5 upgrade_status.admin.inc \upgrade_status_calculate_project_data()
  2. 6 upgrade_status.compare.inc \upgrade_status_calculate_project_data()

Calculates the current update status of all projects on the site.

The results of this function are expensive to compute, especially on sites with lots of modules or themes, since it involves a lot of comparisons and other operations. Therefore, we cache the results into the {cache_update} table using the 'update_project_data' cache ID. However, since this is not the data about available updates fetched from the network, it is ok to invalidate it somewhat quickly. If we keep this data for very long, site administrators are more likely to see incorrect results if they upgrade to a newer version of a module or theme but do not visit certain pages that automatically clear this cache.

Parameters

array $available: Data about available project releases.

Return value

An array of installed projects with current update status information.

See also

upgrade_status_get_available()

update_get_projects()

update_process_project_info()

update_project_cache()

1 call to upgrade_status_calculate_project_data()
upgrade_status_status in ./upgrade_status.report.inc
Page callback: Generates a page about the update status of projects.

File

./upgrade_status.compare.inc, line 34

Code

function upgrade_status_calculate_project_data($available) {

  // Retrieve the projects from cache, if present.

  #  $projects = update_project_cache('upgrade_status_project_data');

  // US: Directly use private cache getter to skip Update's cache invalidation.
  $projects = _update_cache_get('upgrade_status_project_data');

  // If $projects is empty, then the cache must be rebuilt.
  // Otherwise, return the cached data and skip the rest of the function.
  if (!empty($projects)) {

    // US: Return only the data part, not entire $projects array.
    return $projects->data;
  }
  $projects = update_get_projects();

  // US: Handle obsolete projects.
  foreach ($projects as $key => $project) {
    if (upgrade_status_obsolete($projects, $key)) {

      // Add the project that makes this one obsolete to the list of those to
      // grab information about.
      foreach ($projects[$key]['replaced_by'] as $replacement) {
        $projects[$replacement['name']] = $available[$replacement['name']];
        $projects[$replacement['name']]['info'] = array();
      }
    }
  }
  update_process_project_info($projects);
  foreach ($projects as $project => $project_info) {
    if (isset($available[$project])) {
      upgrade_status_calculate_project_update_status($project, $projects[$project], $available[$project]);
    }
    elseif (upgrade_status_obsolete($projects, $project)) {
      $projects[$project]['status'] = UPGRADE_STATUS_OBSOLETE;
      $projects[$project]['reason'] = t('Made obsolete by');
    }
    else {
      $projects[$project]['status'] = UPDATE_UNKNOWN;
      $projects[$project]['reason'] = t('No available releases found');
    }
  }

  // Give other modules a chance to alter the status (for example, to allow a
  // contrib module to provide fine-grained settings to ignore specific
  // projects or releases).
  drupal_alter('update_status', $projects);

  // US: Same for us, afterwards.
  drupal_alter('upgrade_status', $projects);

  // Cache the site's update status for at most 1 hour.
  _update_cache_set('upgrade_status_project_data', $projects, REQUEST_TIME + 3600);
  return $projects;
}