function _upgrade_status_process_fetch_task in Upgrade Status 7
Processes a task to fetch available update data for a single project.
Once the release history XML data is downloaded, it is parsed and saved into the {cache_update} table in an entry just for that project.
Parameters
$project: Associative array of information about the project to fetch data for.
Return value
TRUE if we fetched parsable XML, otherwise FALSE.
2 calls to _upgrade_status_process_fetch_task()
- upgrade_status_fetch_data_batch in ./
upgrade_status.fetch.inc - Batch callback: Processes a step in batch for fetching available update data.
- _upgrade_status_fetch_data in ./
upgrade_status.fetch.inc - Attempts to drain the queue of tasks for release history data to fetch.
File
- ./
upgrade_status.fetch.inc, line 105
Code
function _upgrade_status_process_fetch_task($project) {
global $base_url;
$fail =& drupal_static(__FUNCTION__, array());
// This can be in the middle of a long-running batch, so REQUEST_TIME won't
// necessarily be valid.
$now = time();
if (empty($fail)) {
// If we have valid data about release history XML servers that we have
// failed to fetch from on previous attempts, load that from the cache.
if (($cache = _update_cache_get('upgrade_status_fetch_failures')) && $cache->expire > $now) {
$fail = $cache->data;
}
}
$max_fetch_attempts = variable_get('update_max_fetch_attempts', UPDATE_MAX_FETCH_ATTEMPTS);
$success = FALSE;
$available = array();
// US: No site key to avoid hi-jacking module usage statistics.
# $site_key = drupal_hmac_base64($base_url, drupal_get_private_key());
// US: However, we want to check against a future core version.
$version = variable_get('upgrade_status_core_version', UPGRADE_STATUS_CORE_VERSION);
$url = _upgrade_status_build_fetch_url($project, $version);
$fetch_url_base = _update_get_fetch_url_base($project);
$project_name = $project['name'];
if (empty($fail[$fetch_url_base]) || $fail[$fetch_url_base] < $max_fetch_attempts) {
$xml = drupal_http_request($url);
if (!isset($xml->error) && isset($xml->data)) {
$data = $xml->data;
}
}
if (!empty($data)) {
$available = update_parse_xml($data);
// @todo: Purge release data we don't need (http://drupal.org/node/238950).
// Only if we fetched and parsed something sane (including empty lists from
// projects with no upgrades) do we return success.
$success = TRUE;
}
else {
$available['project_status'] = 'not-fetched';
if (empty($fail[$fetch_url_base])) {
$fail[$fetch_url_base] = 1;
}
else {
$fail[$fetch_url_base]++;
}
}
$frequency = variable_get('update_check_frequency', 1);
$cid = 'upgrade_status_available_releases::' . $project_name;
_update_cache_set($cid, $available, $now + 60 * 60 * 24 * $frequency);
// Stash the $fail data back in the DB for the next 5 minutes.
_update_cache_set('upgrade_status_fetch_failures', $fail, $now + 60 * 5);
// Whether this worked or not, we did just (try to) check for updates.
variable_set('upgrade_status_last_check', $now);
// Now that we processed the fetch task for this project, clear out the
// record in {cache_update} for this task so we're willing to fetch again.
_update_cache_clear('upgrade_status_fetch_task::' . $project_name);
return $success;
}