function _prod_monitor_update_refresh in Production check & Production monitor 6
Same name and namespace in other branches
- 7 prod_monitor/includes/prod_monitor.update.inc \_prod_monitor_update_refresh()
Taken from Core: modules/update/update.fetch.inc, line 25 and MODIFIED!
Fetch project info via XML from a central server.
3 calls to _prod_monitor_update_refresh()
- prod_monitor_fetch_all_data_batcher in prod_monitor/
includes/ prod_monitor.admin.inc - Batch fetching of all site info.
- prod_monitor_updates_check in prod_monitor/
includes/ prod_monitor.admin.inc - Callback to refresh the module update status page
- _drush_prod_monitor_update_refresh in prod_monitor/
prod_monitor.drush.inc - Helper function to refresh update status data.
File
- prod_monitor/
includes/ prod_monitor.update.inc, line 17
Code
function _prod_monitor_update_refresh($id, $projects, $site_key) {
static $fail = array();
global $base_url;
// contains update_xml_parser class
module_load_include('inc', 'update', 'update.fetch');
$available = array();
$data = array();
// As replacement for DRUPAL_CORE_COMPATIBILITY since prod_check and
// prod_monitor should be site independant.
$core = explode('.', $projects['drupal']['info']['version']);
$core = $core[0] . '.x';
$max_fetch_attempts = UPDATE_MAX_FETCH_ATTEMPTS;
// Prepare object to store generated data to DB.
$modules = new stdClass();
$modules->id = $id;
foreach ($projects as $key => $project) {
$url = _prod_monitor_update_build_fetch_url($project, $site_key, $core);
$fetch_url_base = _prod_monitor_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 {
// 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_xml_parser();
$available = $parser
->parse($data);
}
if (!empty($available) && is_array($available)) {
// 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';
}
}
$modules->available = serialize($available);
watchdog('prod_monitor', 'Attempted to fetch information about all available new releases and updates for %link.', array(
'%link' => _prod_monitor_get_url($id),
), WATCHDOG_NOTICE, l(t('view'), 'admin/reports/prod-monitor/site/' . $id . '/view/updates'));
}
else {
watchdog('prod_monitor', 'Unable to fetch any information about available new releases and updates for %link.', array(
'%link' => _prod_monitor_get_url($id),
), WATCHDOG_ERROR, l(t('view'), 'admin/reports/prod-monitor/site/' . $id . '/view/updates'));
}
// Whether this worked or not, we did just (try to) check for updates.
$modules->lastupdate = time();
$result = drupal_write_record('prod_monitor_site_modules', $modules, array(
'id',
));
if (!$result) {
watchdog('prod_monitor', 'Could not update module data for %link', array(
'%link' => _prod_monitor_get_url($id),
), WATCHDOG_ERROR);
}
return $available;
}