function _git_deploy_update_refresh in Git Deploy 6.2
Same name and namespace in other branches
- 6 git_deploy.module \_git_deploy_update_refresh()
Updates available release data given a list of projects.
We need this because loading projects within the function that fetches available releases would start an endless loop.
Parameters
array[] $projects: List of available projects.
Return value
array[] List of available releases, keyed by project name.
See also
_mydropwizard_refresh()
1 call to _git_deploy_update_refresh()
- git_deploy_mydropwizard_projects_alter in ./
git_deploy.module - Implements hook_mydropwizard_projects_alter().
File
- ./
git_deploy.module, line 335 - Adds project, version and date information to projects checked out with Git.
Code
function _git_deploy_update_refresh($projects) {
static $fail = array();
global $base_url;
module_load_include('inc', 'mydropwizard', 'mydropwizard.compare');
// 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
// mydropwizard_get_projects(); for example, to modules that implement
// hook_system_info_alter() such as cvs_deploy.
_mydropwizard_cache_clear('mydropwizard_project_projects');
_mydropwizard_cache_clear('mydropwizard_project_data');
$available = array();
$data = array();
$site_key = md5($base_url . drupal_get_private_key());
// 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.
_mydropwizard_cache_clear('mydropwizard_available_releases');
$max_fetch_attempts = variable_get('mydropwizard_max_fetch_attempts', UPDATE_MAX_FETCH_ATTEMPTS);
// Call back to the server to share staistics, and see if we're using an
// out-of-date version of the mydropwizard module.
$project_versions = array();
foreach ($projects as $key => $project) {
if (strpos($project['project_type'], 'disabled') === FALSE) {
if (!empty($project['info']['version'])) {
$version = $project['info']['version'];
}
else {
// Stub version to encode the core compatibility.
$version = DRUPAL_CORE_COMPATIBILITY;
}
$project_versions[$key] = $version;
}
}
$statistics_url = variable_get('mydropwizard_statistics_url', MYDROPWIZARD_STATISTICS_URL);
$statistics_data = drupal_to_js(array(
'site_key' => $site_key,
'projects' => $project_versions,
'mydropwizard_key' => variable_get('mydropwizard_customer_key', ''),
));
if (variable_get('mydropwizard_http_post_disabled', FALSE)) {
// This is a hack for a customer site that seemingly can't do HTTP POST
// for mysterious reasons. I don't like it, but it works.
$response = drupal_http_request($statistics_url . '?data=' . base64_encode($statistics_data));
}
else {
$response = drupal_http_request($statistics_url, array(
'Content-type' => 'application/json',
), 'POST', $statistics_data);
}
$update_status = $response->data;
variable_set('mydropwizard_update_status', $update_status);
// If the server says we're good, then pull the individual status for each project.
if ($update_status == 'OK' || variable_get('mydropwizard_ignore_statistics_errors', FALSE)) {
module_load_include('inc', 'mydropwizard', 'mydropwizard.fetch');
foreach ($projects as $key => $project) {
$url = _mydropwizard_build_fetch_url($project, $site_key);
$fetch_url_base = _mydropwizard_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 mydropwizard_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';
}
}
$frequency = variable_get('mydropwizard_check_frequency', 1);
_mydropwizard_cache_set('mydropwizard_available_releases', $available, time() + 60 * 60 * 24 * $frequency);
watchdog('mydropwizard', 'Attempted to fetch information about all available new releases and updates.', array(), WATCHDOG_NOTICE, l(t('view'), 'admin/reports/updates'));
}
else {
watchdog('mydropwizard', 'Unable to fetch any information about available new releases and updates.', array(), WATCHDOG_ERROR, l(t('view'), 'admin/reports/updates'));
}
// Whether this worked or not, we did just (try to) check for updates.
variable_set('mydropwizard_last_check', time());
return $available;
}