function update_status_refresh in Update Status 5.2
Same name and namespace in other branches
- 5 update_status.module \update_status_refresh()
Fetch project info via XML from a central server.
3 calls to update_status_refresh()
- update_status_cron in ./
update_status.module - Implementation of hook_cron().
- update_status_get_available in ./
update_status.module - Internal helper to try to get the update information from the cache if possible, and to refresh the cache when necessary.
- update_status_manual_status in ./
update_status.module - Callback to manually check the update status without cron.
File
- ./
update_status.module, line 1520
Code
function update_status_refresh() {
global $base_url;
static $fail = array();
// Since we're fetching new available update data, we want to clear
// our cache of both the projects we care about, and the current update
// status of the site. We do *not* want to clear the cache of available
// releases just yet, since that data (even if it's stale) can be useful
// during update_status_get_projects(); for example, to modules that
// implement hook_system_info_alter() such as cvs_deploy.
_update_status_cache_clear('update_status_project_projects');
_update_status_cache_clear('update_status_project_data');
// If not in 'safe mode', increase the maximum execution time:
if (!ini_get('safe_mode')) {
set_time_limit(300);
}
$available = array();
$data = array();
$site_key = md5($base_url . drupal_get_private_key());
$projects = update_status_get_projects();
// Now that we have the list of projects, we should also clear our cache of
// available release data, since even if we fail to fetch new data, we need
// to clear out the stale data at this point.
_update_status_cache_clear('update_status_available_releases');
$max_fetch_attempts = variable_get('update_status_max_fetch_attempts', UPDATE_STATUS_MAX_FETCH_ATTEMPTS);
foreach ($projects as $key => $project) {
$url = _update_status_build_fetch_url($project, $site_key);
$fetch_url_base = _update_status_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 {
// Connection likely broken; prepare to give up.
$fail[$fetch_url_base][$key] = 1;
}
}
else {
// Didn't bother trying to fetch.
$fail[$fetch_url_base][$key] = 1;
}
}
if ($data) {
$parser = new update_status_xml_parser();
$available = $parser
->parse($data);
// Record the projects where we failed to fetch data.
foreach ($fail as $fetch_url_base => $failures) {
foreach ($failures as $key => $value) {
$available[$key]['project_status'] = 'not-fetched';
}
}
_update_status_cache_set('update_status_available_releases', serialize($available), time() + 60 * 60 * 24);
watchdog('update_status', t('Attempted to fetch information about all available new releases and updates.'), WATCHDOG_NOTICE, l(t('view'), 'admin/logs/updates'));
}
else {
watchdog('update_status', 'Unable to fetch any information on available new releases and updates.', WATCHDOG_ERROR, l(t('view'), 'admin/logs/updates'));
}
// Whether this worked or not, we did just (try to) check for updates.
variable_set('update_status_last', time());
return $available;
}