You are here

function upgrade_status_get_available in Upgrade Status 7

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

Tries to get update information from cache and refreshes it when necessary.

In addition to checking the cache lifetime, this function also ensures that there are no .info files for enabled modules or themes that have a newer modification timestamp than the last time we checked for available update data. If any .info file was modified, it almost certainly means a new version of something was installed. Without fresh available update data, the logic in update_calculate_project_data() will be wrong and produce confusing, bogus results.

Parameters

$refresh: (optional) Boolean to indicate if this method should refresh the cache automatically if there's no data. Defaults to FALSE.

Return value

Array of data about available releases, keyed by project shortname.

See also

upgrade_status_refresh()

update_get_projects()

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

File

./upgrade_status.module, line 108
Checks to see if your installed modules are available for the next major release of Drupal.

Code

function upgrade_status_get_available($refresh = FALSE) {
  module_load_include('inc', 'upgrade_status', 'upgrade_status.compare');
  $needs_refresh = FALSE;

  // Grab whatever data we currently have cached in the DB.
  $available = _upgrade_status_get_cached_available_releases();
  $num_avail = count($available);
  $projects = update_get_projects();
  foreach ($projects as $key => $project) {

    // If there's no data at all, we clearly need to fetch some.
    if (empty($available[$key])) {
      upgrade_status_create_fetch_task($project);
      $needs_refresh = TRUE;
      continue;
    }

    // See if the .info file is newer than the last time we checked for data,
    // and if so, mark this project's data as needing to be re-fetched. Any
    // time an admin upgrades their local installation, the .info file will
    // be changed, so this is the only way we can be sure we're not showing
    // bogus information right after they upgrade.
    if ($project['info']['_info_file_ctime'] > $available[$key]['last_fetch']) {
      $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
    }

    // If we have project data but no release data, we need to fetch. This
    // can be triggered when we fail to contact a release history server.
    if (empty($available[$key]['releases'])) {
      $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
    }

    // If we think this project needs to fetch, actually create the task now
    // and remember that we think we're missing some data.
    if (!empty($available[$key]['fetch_status']) && $available[$key]['fetch_status'] == UPDATE_FETCH_PENDING) {
      upgrade_status_create_fetch_task($project);
      $needs_refresh = TRUE;
    }
  }
  if ($needs_refresh && $refresh) {

    // Attempt to drain the queue of fetch tasks.
    upgrade_status_fetch_data();

    // After processing the queue, we've (hopefully) got better data, so pull
    // the latest from the cache again and use that directly.
    $available = _upgrade_status_get_cached_available_releases();
  }
  return $available;
}