upgrade_status.fetch.inc in Upgrade Status 6
File
upgrade_status.fetch.inc
View source
<?php
module_load_include('inc', 'update', 'update.fetch');
function upgrade_status_manual_status() {
if (_upgrade_status_refresh()) {
drupal_set_message(t('Attempted to fetch information about all available new releases and upgrades.'));
}
else {
drupal_set_message(t('Unable to fetch any information about available new releases and updates.'), 'error');
}
drupal_goto('admin/reports/updates/upgrade');
}
function _upgrade_status_refresh() {
static $fail = array();
global $base_url;
module_load_include('inc', 'upgrade_status', 'upgrade_status.compare');
@set_time_limit(240);
_update_cache_clear('upgrade_status_project_projects');
_update_cache_clear('upgrade_status_project_data');
$available = array();
$data = array();
$projects = update_get_projects();
$version = variable_get('upgrade_status_core_version', UPGRADE_STATUS_CORE_VERSION);
_update_cache_clear('upgrade_status_available_releases');
$max_fetch_attempts = variable_get('update_max_fetch_attempts', UPDATE_MAX_FETCH_ATTEMPTS);
foreach ($projects as $key => $project) {
$url = _upgrade_status_build_fetch_url($project, $version);
$fetch_url_base = _update_get_fetch_url_base($project);
if (empty($fail[$fetch_url_base]) || count($fail[$fetch_url_base]) < $max_fetch_attempts) {
$xml = drupal_http_request($url);
if (isset($xml->data)) {
$data[] = $xml->data;
}
else {
$fail[$fetch_url_base][$key] = 1;
}
}
else {
$fail[$fetch_url_base][$key] = 1;
}
}
if ($data) {
$parser = new update_xml_parser();
$available = $parser
->parse($data);
}
if (!empty($available) && is_array($available)) {
foreach ($fail as $fetch_url_base => $failures) {
foreach ($failures as $key => $value) {
$available[$key]['project_status'] = 'not-fetched';
}
}
$frequency = variable_get('upgrade_status_check_frequency', 1);
_update_cache_set('upgrade_status_available_releases', $available, time() + 60 * 60 * 24 * $frequency);
watchdog('upgrade_status', 'Attempted to fetch information about all available new releases and updates.', array(), WATCHDOG_NOTICE, l(t('view'), 'admin/reports/updates/upgrade'));
}
else {
watchdog('upgrade_status', 'Unable to fetch any information about available new releases and updates.', array(), WATCHDOG_ERROR, l(t('view'), 'admin/reports/updates/upgrade'));
}
variable_set('upgrade_status_last_check', time());
return $available;
}
function _upgrade_status_build_fetch_url($project, $version) {
$name = $project['name'];
$url = _update_get_fetch_url_base($project);
$url .= '/' . $name . '/' . $version;
return $url;
}