The "Update status" module checks for available updates of Drupal core and
any installed contributed modules and themes. It warns site administrators
if newer releases are available via the system status report
(admin/reports/status), the module and theme pages, and optionally via email.
View source
<?php
define('UPDATE_DEFAULT_URL', 'http://updates.drupal.org/release-history');
define('UPDATE_NOT_SECURE', 1);
define('UPDATE_REVOKED', 2);
define('UPDATE_NOT_SUPPORTED', 3);
define('UPDATE_NOT_CURRENT', 4);
define('UPDATE_CURRENT', 5);
define('UPDATE_NOT_CHECKED', -1);
define('UPDATE_UNKNOWN', -2);
define('UPDATE_NOT_FETCHED', -3);
define('UPDATE_MAX_FETCH_ATTEMPTS', 2);
function update_help($path, $arg) {
switch ($path) {
case 'admin/reports/updates':
$output = '<p>' . t('Here you can find information about available updates for your installed modules and themes. Note that each module or theme is part of a "project", which may or may not have the same name, and might include multiple modules or themes within it.') . '</p>';
$output .= '<p>' . t('To extend the functionality or to change the look of your site, a number of contributed <a href="@modules">modules</a> and <a href="@themes">themes</a> are available.', array(
'@modules' => 'http://drupal.org/project/modules',
'@themes' => 'http://drupal.org/project/themes',
)) . '</p>';
return $output;
case 'admin/build/themes':
case 'admin/build/modules':
include_once './includes/install.inc';
$status = update_requirements('runtime');
foreach (array(
'core',
'contrib',
) as $report_type) {
$type = 'update_' . $report_type;
if (isset($status[$type]['severity'])) {
if ($status[$type]['severity'] == REQUIREMENT_ERROR) {
drupal_set_message($status[$type]['description'], 'error');
}
elseif ($status[$type]['severity'] == REQUIREMENT_WARNING) {
drupal_set_message($status[$type]['description'], 'warning');
}
}
}
return '<p>' . t('See the <a href="@available_updates">available updates</a> page for information on installed modules and themes with new versions released.', array(
'@available_updates' => url('admin/reports/updates'),
)) . '</p>';
case 'admin/reports/updates/settings':
case 'admin/reports/status':
break;
case 'admin/help#update':
$output = '<p>' . t("The Update status module periodically checks for new versions of your site's software (including contributed modules and themes), and alerts you to available updates.") . '</p>';
$output .= '<p>' . t('The <a href="@update-report">report of available updates</a> will alert you when new releases are available for download. You may configure options for update checking frequency and notifications at the <a href="@update-settings">Update status module settings page</a>.', array(
'@update-report' => url('admin/reports/updates'),
'@update-settings' => url('admin/reports/updates/settings'),
)) . '</p>';
$output .= '<p>' . t('Please note that in order to provide this information, anonymous usage statistics are sent to drupal.org. If desired, you may disable the Update status module from the <a href="@modules">module administration page</a>.', array(
'@modules' => url('admin/build/modules'),
)) . '</p>';
$output .= '<p>' . t('For more information, see the online handbook entry for <a href="@update">Update status module</a>.', array(
'@update' => 'http://drupal.org/handbook/modules/update',
)) . '</p>';
return $output;
default:
if (arg(0) == 'admin' && strpos($path, '#') === FALSE && user_access('administer site configuration')) {
include_once './includes/install.inc';
$status = update_requirements('runtime');
foreach (array(
'core',
'contrib',
) as $report_type) {
$type = 'update_' . $report_type;
if (isset($status[$type]) && isset($status[$type]['reason']) && $status[$type]['reason'] === UPDATE_NOT_SECURE) {
drupal_set_message($status[$type]['description'], 'error');
}
}
}
}
}
function update_menu() {
$items = array();
$items['admin/reports/updates'] = array(
'title' => 'Available updates',
'description' => 'Get a status report about available updates for your installed modules and themes.',
'page callback' => 'update_status',
'access arguments' => array(
'administer site configuration',
),
'file' => 'update.report.inc',
'weight' => 10,
);
$items['admin/reports/updates/list'] = array(
'title' => 'List',
'page callback' => 'update_status',
'access arguments' => array(
'administer site configuration',
),
'file' => 'update.report.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/reports/updates/settings'] = array(
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'update_settings',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'update.settings.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/reports/updates/check'] = array(
'title' => 'Manual update check',
'page callback' => 'update_manual_status',
'access arguments' => array(
'administer site configuration',
),
'file' => 'update.fetch.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
function update_theme() {
return array(
'update_settings' => array(
'arguments' => array(
'form' => NULL,
),
),
'update_report' => array(
'arguments' => array(
'data' => NULL,
),
),
'update_version' => array(
'arguments' => array(
'version' => NULL,
'tag' => NULL,
'class' => NULL,
),
),
);
}
function update_requirements($phase) {
if ($phase == 'runtime') {
if ($available = update_get_available(FALSE)) {
module_load_include('inc', 'update', 'update.compare');
$data = update_calculate_project_data($available);
$requirements['update_core'] = _update_requirement_check($data['drupal'], 'core');
unset($data['drupal']);
if (!empty($data)) {
uasort($data, '_update_project_status_sort');
$first_project = reset($data);
$requirements['update_contrib'] = _update_requirement_check($first_project, 'contrib');
}
}
else {
$requirements['update_core']['title'] = t('Drupal core update status');
$requirements['update_core']['value'] = t('No update data available');
$requirements['update_core']['severity'] = REQUIREMENT_WARNING;
$requirements['update_core']['reason'] = UPDATE_UNKNOWN;
$requirements['update_core']['description'] = _update_no_data();
}
return $requirements;
}
}
function _update_requirement_check($project, $type) {
$requirement = array();
if ($type == 'core') {
$requirement['title'] = t('Drupal core update status');
}
else {
$requirement['title'] = t('Module and theme update status');
}
$status = $project['status'];
if ($status != UPDATE_CURRENT) {
$requirement['reason'] = $status;
$requirement['description'] = _update_message_text($type, $status, TRUE);
$requirement['severity'] = REQUIREMENT_ERROR;
}
switch ($status) {
case UPDATE_NOT_SECURE:
$requirement_label = t('Not secure!');
break;
case UPDATE_REVOKED:
$requirement_label = t('Revoked!');
break;
case UPDATE_NOT_SUPPORTED:
$requirement_label = t('Unsupported release');
break;
case UPDATE_NOT_CURRENT:
$requirement_label = t('Out of date');
$requirement['severity'] = REQUIREMENT_WARNING;
break;
case UPDATE_UNKNOWN:
case UPDATE_NOT_CHECKED:
case UPDATE_NOT_FETCHED:
$requirement_label = isset($project['reason']) ? $project['reason'] : t('Can not determine status');
$requirement['severity'] = REQUIREMENT_WARNING;
break;
default:
$requirement_label = t('Up to date');
}
if ($status != UPDATE_CURRENT && $type == 'core' && isset($project['recommended'])) {
$requirement_label .= ' ' . t('(version @version available)', array(
'@version' => $project['recommended'],
));
}
$requirement['value'] = l($requirement_label, 'admin/reports/updates');
return $requirement;
}
function update_cron() {
$frequency = variable_get('update_check_frequency', 1);
$interval = 60 * 60 * 24 * $frequency;
if (!_update_cache_get('update_available_releases') || time() - variable_get('update_last_check', 0) > $interval) {
update_refresh();
_update_cron_notify();
}
}
function update_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'system_modules' || $form_id == 'system_themes_form') {
$form['#submit'][] = 'update_invalidate_cache';
}
}
function _update_no_data() {
$destination = drupal_get_destination();
return t('No information is available about potential new releases for currently installed modules and themes. To check for updates, you may need to <a href="@run_cron">run cron</a> or you can <a href="@check_manually">check manually</a>. Please note that checking for available updates can take a long time, so please be patient.', array(
'@run_cron' => url('admin/reports/status/run-cron', array(
'query' => $destination,
)),
'@check_manually' => url('admin/reports/updates/check', array(
'query' => $destination,
)),
));
}
function update_get_available($refresh = FALSE) {
module_load_include('inc', 'update', 'update.compare');
$available = array();
$needs_refresh = FALSE;
$last_check = variable_get('update_last_check', 0);
$projects = update_get_projects();
foreach ($projects as $key => $project) {
if ($project['info']['_info_file_ctime'] > $last_check) {
$needs_refresh = TRUE;
break;
}
}
if (!$needs_refresh && ($cache = _update_cache_get('update_available_releases')) && $cache->expire > time()) {
$available = $cache->data;
}
elseif ($needs_refresh || $refresh) {
$available = update_refresh();
}
return $available;
}
function update_refresh() {
module_load_include('inc', 'update', 'update.fetch');
return _update_refresh();
}
function update_mail($key, &$message, $params) {
$language = $message['language'];
$langcode = $language->language;
$message['subject'] .= t('New release(s) available for !site_name', array(
'!site_name' => variable_get('site_name', 'Drupal'),
), $langcode);
foreach ($params as $msg_type => $msg_reason) {
$message['body'][] = _update_message_text($msg_type, $msg_reason, FALSE, $language);
}
$message['body'][] = t('See the available updates page for more information:', array(), $langcode) . "\n" . url('admin/reports/updates', array(
'absolute' => TRUE,
'language' => $language,
));
}
function _update_message_text($msg_type, $msg_reason, $report_link = FALSE, $language = NULL) {
$langcode = isset($language) ? $language->language : NULL;
$text = '';
switch ($msg_reason) {
case UPDATE_NOT_SECURE:
if ($msg_type == 'core') {
$text = t('There is a security update available for your version of Drupal. To ensure the security of your server, you should update immediately!', array(), $langcode);
}
else {
$text = t('There are security updates available for one or more of your modules or themes. To ensure the security of your server, you should update immediately!', array(), $langcode);
}
break;
case UPDATE_REVOKED:
if ($msg_type == 'core') {
$text = t('Your version of Drupal has been revoked and is no longer available for download. Upgrading is strongly recommended!', array(), $langcode);
}
else {
$text = t('The installed version of at least one of your modules or themes has been revoked and is no longer available for download. Upgrading or disabling is strongly recommended!', array(), $langcode);
}
break;
case UPDATE_NOT_SUPPORTED:
if ($msg_type == 'core') {
$text = t('Your version of Drupal is no longer supported. Upgrading is strongly recommended!', array(), $langcode);
}
else {
$text = t('The installed version of at least one of your modules or themes is no longer supported. Upgrading or disabling is strongly recommended! Please see the project homepage for more details.', array(), $langcode);
}
break;
case UPDATE_NOT_CURRENT:
if ($msg_type == 'core') {
$text = t('There are updates available for your version of Drupal. To ensure the proper functioning of your site, you should update as soon as possible.', array(), $langcode);
}
else {
$text = t('There are updates available for one or more of your modules or themes. To ensure the proper functioning of your site, you should update as soon as possible.', array(), $langcode);
}
break;
case UPDATE_UNKNOWN:
case UPDATE_NOT_CHECKED:
case UPDATE_NOT_FETCHED:
if ($msg_type == 'core') {
$text = t('There was a problem determining the status of available updates for your version of Drupal.', array(), $langcode);
}
else {
$text = t('There was a problem determining the status of available updates for one or more of your modules or themes.', array(), $langcode);
}
break;
}
if ($report_link) {
$text .= ' ' . t('See the <a href="@available_updates">available updates</a> page for more information.', array(
'@available_updates' => url('admin/reports/updates', array(
'language' => $language,
)),
), $langcode);
}
return $text;
}
function _update_project_status_sort($a, $b) {
$a_status = $a['status'] > 0 ? $a['status'] : -10 * $a['status'];
$b_status = $b['status'] > 0 ? $b['status'] : -10 * $b['status'];
return $a_status - $b_status;
}
function _update_cache_set($cid, $data, $expire) {
$serialized = 0;
if (is_object($data) || is_array($data)) {
$data = serialize($data);
$serialized = 1;
}
$created = time();
db_query("UPDATE {cache_update} SET data = %b, created = %d, expire = %d, serialized = %d WHERE cid = '%s'", $data, $created, $expire, $serialized, $cid);
if (!db_affected_rows()) {
@db_query("INSERT INTO {cache_update} (cid, data, created, expire, serialized) VALUES ('%s', %b, %d, %d, %d)", $cid, $data, $created, $expire, $serialized);
}
}
function _update_cache_get($cid) {
$cache = db_fetch_object(db_query("SELECT data, created, expire, serialized FROM {cache_update} WHERE cid = '%s'", $cid));
if (isset($cache->data)) {
$cache->data = db_decode_blob($cache->data);
if ($cache->serialized) {
$cache->data = unserialize($cache->data);
}
}
return $cache;
}
function _update_cache_clear($cid = NULL) {
if (empty($cid)) {
db_query("TRUNCATE TABLE {cache_update}");
}
else {
db_query("DELETE FROM {cache_update} WHERE cid = '%s'", $cid);
}
}
function update_flush_caches() {
if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
_update_cache_clear();
}
return array();
}
function update_invalidate_cache() {
_update_cache_clear();
}