Commit 6ec2ff7e authored by Dries's avatar Dries

- Patch #94154 by dww, Earl et al: update notifications for Drupal!

  Woot, woot! :)
parent 70f9297c
......@@ -62,6 +62,7 @@ Drupal 6.0, xxxx-xx-xx (development version)
- Added support for OpenID.
- Added support for configurable actions.
- Made user profiles easier to theme by using array rendering and supplying template files.
- Added the Update status module to automatically check for available updates and warn sites if they are missing security updates or newer versions.
Drupal 5.0, 2007-01-15
----------------------
......
......@@ -66,6 +66,11 @@ STATISTICS MODULE
M: Jeremy Andrews <jeremy@kerneltrap.com>
S: maintained
UPDATE MODULE
M: Derek Wright <http://drupal.org/user/46549/contact>
Earl Miles <http://drupal.org/user/26979/contact>
S: maintained
XML-RPC SERVER/CLIENT
M: John VanDyk <http://drupal.org/user/2375/contact>
S: maintained
......
......@@ -444,7 +444,7 @@ function menu_edit_menu_validate($form, &$form_state) {
}
if ($form['#insert']) {
// We will add 'menu-' to the menu name to help avoid name-space conflicts.
$item['menu_name'] = 'menu-'. $item['menu_name'];
$item['menu_name'] = 'menu-'. $item['menu_name'];
if (db_result(db_query("SELECT menu_name FROM {menu_custom} WHERE menu_name = '%s'", $item['menu_name'])) ||
db_result(db_query_range("SELECT menu_name FROM {menu_links} WHERE menu_name = '%s'", $item['menu_name'], 0, 1))) {
form_set_error('menu_name', t('Menu already exists'));
......
......@@ -3439,6 +3439,41 @@ function system_update_6025() {
return $ret;
}
/**
* Enable the update.module by default on sites that upgrade.
*
* This cannot just rely on update.install to install the schema. If,
* in the future, someone decides to change the schema for the
* {cache_update} table, this update would cause uncertainty in the
* state of the DB, since the effect of running this update would
* change. For example, if the schema is changed in update #6101, and
* a site upgrades direct from 5.x to 6.1, update #6026 would create
* the table with the new schema, and then update #6101 would fail,
* since it's trying to alter the old schema into the new
* schema. Therefore, we must hard-code the particular version of the
* schema we mean during update #6026, and then future upgrades that
* might attempt to modify the schema of this table will be starting
* from a known state. See http://drupal.org/node/150220 for more.
*/
function system_update_6026() {
$ret = array();
$schema['cache_update'] = array(
'fields' => array(
'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'headers' => array('type' => 'text', 'not null' => FALSE),
'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
),
'indexes' => array('expire' => array('expire')),
'primary key' => array('cid'),
);
db_create_table($ret, 'cache_update', $schema['cache_update']);
module_enable(array('update'));
menu_rebuild();
return $ret;
}
/**
* @} End of "defgroup updates-5.x-to-6.x"
......
/* $Id$ */
.update .project {
padding-right: .25em;
}
.update .version-status {
float: left;
padding-left: 10px;
}
.update .version-status .icon {
padding-right: .5em;
}
.update table.version .version-title {
padding-left: 1em;
}
.update table.version .version-details {
padding-left: .5em;
}
.update table.version .version-links {
text-align: left;
padding-left: 1em;
}
This diff is collapsed.
/* $Id$ */
.update .project {
font-weight: bold;
font-size: 110%;
padding-left: .25em; /* LTR */
height: 22px;
}
.update .version-status {
float: right; /* LTR */
padding-right: 10px; /* LTR */
font-size: 110%;
height: 20px;
}
.update .version-status .icon {
padding-left: .5em; /* LTR */
}
.update .info {
margin: 0;
padding: 1em 1em .25em 1em;
}
.update tr td {
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
}
.update tr.error {
background: #fcc;
}
.update tr.error .version-recommended {
background: #fdd;
}
.update tr.ok {
background: #dfd;
}
.update tr.warning {
background: #ffd;
}
.update tr.warning .version-recommended {
background: #ffe;
}
.current-version, .new-version {
direction: ltr; /* Note: version numbers should always be LTR. */
}
table.update,
.update table.version {
width: 100%;
margin-top: .5em;
}
.update table.version tbody {
border: none;
}
.update table.version tr,
.update table.version td {
line-height: .9em;
padding: 0;
margin: 0;
border: none;
}
.update table.version .version-title {
padding-left: 1em; /* LTR */
width: 14em;
}
.update table.version .version-details {
padding-right: .5em; /* LTR */
}
.update table.version .version-links {
text-align: right; /* LTR */
padding-right: 1em; /* LTR */
}
.update table.version-security .version-title {
color: #970F00;
}
.update table.version-recommended-strong .version-title {
font-weight: bold;
}
.update .security-error {
font-weight: bold;
color: #970F00;
}
<?php
// $Id$
/**
* @file
* Code required only when fetching information about available updates.
*/
/**
* Callback to manually check the update status without cron.
*/
function update_manual_status() {
if (_update_refresh()) {
drupal_set_message(t('Fetched information about all available new releases and updates.'));
}
else {
drupal_set_message(t('Unable to fetch any information on available new releases and updates.'), 'error');
}
drupal_goto('admin/logs/updates');
}
/**
* Fetch project info via XML from a central server.
*/
function _update_refresh() {
global $base_url;
include_once './modules/update/update.compare.inc';
$available = array();
$data = array();
$site_key = '';
$drupal_private_key = variable_get('drupal_private_key', '');
$site_key = md5($base_url . $drupal_private_key);
$projects = update_get_projects();
foreach ($projects as $key => $project) {
$url = _update_build_fetch_url($project, $site_key);
$xml = drupal_http_request($url);
if (isset($xml->data)) {
$data[] = $xml->data;
}
}
if ($data) {
$parser = new update_xml_parser;
$available = $parser->parse($data);
$frequency = variable_get('update_check_frequency', 1);
cache_set('update_info', $available, 'cache_update', time() + (60 * 60 * 24 * $frequency));
variable_set('update_last_check', time());
watchdog('update', 'Fetched information on all available new releases and updates.', array(), WATCHDOG_NOTICE, l('view', 'admin/logs/updates'));
}
else {
watchdog('update', 'Unable to fetch any information on available new releases and updates.', array(), WATCHDOG_ERROR, l('view', 'admin/logs/updates'));
}
return $available;
}
/**
* Generates the URL to fetch information about project updates.
*
* This figures out the right URL to use, based on the project's .info file
* and the global defaults. Appends optional query arguments when the site is
* configured to report usage stats.
*
* @param $project
* The array of project information from update_get_projects().
* @param $site_key
* The anonymous site key hash (optional).
*
* @see update_refresh()
* @see update_get_projects()
*/
function _update_build_fetch_url($project, $site_key = '') {
$default_url = variable_get('update_fetch_url', UPDATE_DEFAULT_URL);
if (!isset($project['info']['project status url'])) {
$project['info']['project status url'] = $default_url;
}
$name = $project['name'];
$url = $project['info']['project status url'];
$url .= '/'. $name .'/'. DRUPAL_CORE_COMPATIBILITY;
if (!empty($site_key)) {
$url .= (strpos($url, '?') === TRUE) ? '&' : '?';
$url .= 'site_key=';
$url .= drupal_urlencode($site_key);
if (!empty($project['info']['version'])) {
$url .= '&version=';
$url .= drupal_urlencode($project['info']['version']);
}
}
return $url;
}
/**
* Perform any notifications that should be done once cron fetches new data.
*
* This method checks the status of the site using the new data and depending
* on the configuration of the site, notifys administrators via email if there
* are new releases or missing security updates.
*
* @see update_requirements()
*/
function _update_cron_notify() {
include_once './includes/install.inc';
$status = update_requirements('runtime');
$params = array();
foreach (array('core', 'contrib') as $report_type) {
$type = 'update_'. $report_type;
if (isset($status[$type]['severity'])
&& $status[$type]['severity'] == REQUIREMENT_ERROR) {
$params[$report_type] = $status[$type]['reason'];
}
}
if (!empty($params)) {
$notify_list = variable_get('update_notify_emails', '');
if (!empty($notify_list)) {
$default_language = language_default();
foreach ($notify_list as $target) {
if ($target_user = user_load(array('mail' => $target))) {
$target_language = user_preferred_language($target_user);
}
else {
$target_language = $default_language;
}
drupal_mail('update', 'status_notify', $target, $target_language, $params);
}
}
}
}
/**
* XML Parser object to read Drupal's release history info files.
* This uses PHP4's lame XML parsing, but it works.
*/
class update_xml_parser {
var $projects = array();
var $current_project;
var $current_release;
var $current_term;
var $current_tag;
var $current_object;
/**
* Parse an array of XML data files.
*/
function parse($data) {
foreach ($data as $datum) {
$parser = xml_parser_create();
xml_set_object($parser, $this);
xml_set_element_handler($parser, 'start', 'end');
xml_set_character_data_handler($parser, "data");
xml_parse($parser, $datum);
xml_parser_free($parser);
}
return $this->projects;
}
function start($parser, $name, $attr) {
$this->current_tag = $name;
switch ($name) {
case 'PROJECT':
unset($this->current_object);
$this->current_project = array();
$this->current_object = &$this->current_project;
break;
case 'RELEASE':
unset($this->current_object);
$this->current_release = array();
$this->current_object = &$this->current_release;
break;
case 'TERM':
unset($this->current_object);
$this->current_term = array();
$this->current_object = &$this->current_term;
break;
}
}
function end($parser, $name) {
switch ($name) {
case 'PROJECT':
unset($this->current_object);
$this->projects[$this->current_project['short_name']] = $this->current_project;
$this->current_project = array();
break;
case 'RELEASE':
unset($this->current_object);
$this->current_project['releases'][$this->current_release['version']] = $this->current_release;
break;
case 'RELEASES':
$this->current_object = &$this->current_project;
break;
case 'TERM':
unset($this->current_object);
$term_name = $this->current_term['name'];
if (!isset($this->current_release['terms'])) {
$this->current_release['terms'] = array();
}
if (!isset($this->current_release['terms'][$term_name])) {
$this->current_release['terms'][$term_name] = array();
}
$this->current_release['terms'][$term_name][] = $this->current_term['value'];
break;
case 'TERMS':
$this->current_object = &$this->current_release;
break;
default:
$this->current_object[strtolower($this->current_tag)] = trim($this->current_object[strtolower($this->current_tag)]);
$this->current_tag = '';
}
}
function data($parser, $data) {
if ($this->current_tag && !in_array($this->current_tag, array('PROJECT', 'RELEASE', 'RELEASES', 'TERM', 'TERMS'))) {
$tag = strtolower($this->current_tag);
if (isset($this->current_object[$tag])) {
$this->current_object[$tag] .= $data;
}
else {
$this->current_object[$tag] = $data;
}
}
}
}
; $Id$
name = Update status
description = Checks the status of available updates for Drupal and your installed modules and themes.
version = VERSION
package = Core - optional
core = 6.x
<?php
// $Id$
/**
* Implementation of hook_install().
*/
function update_install() {
// Create cache table.
drupal_install_schema('update');
}
/**
* Implementation of hook_uninstall().
*/
function update_uninstall() {
// Remove cache table.
drupal_uninstall_schema('update');
// Clear any variables that might be in use
$variables = array(
'update_check_frequency',
'update_fetch_url',
'update_last_check',
'update_notification_threshold',
'update_notify_emails',
);
foreach ($variables as $variable) {
variable_del($variable);
}
menu_rebuild();
}
This diff is collapsed.
<?php
// $Id$
/**
* @file
* Code required only when rendering the available updates report.
*/
/**
* Menu callback. Generate a page about the update status of projects.
*/
function update_status() {
if ($available = update_get_available(TRUE)) {
include_once './modules/update/update.compare.inc';
$data = update_calculate_project_data($available);
return theme('update_report', $data);
}
else {
return theme('update_report', _update_no_data());
}
}
/**
* Theme project status report.
*/
function theme_update_report($data) {
$last = variable_get('update_last_check', 0);
$output = '<div class="checked">'. t('Last checked: ') . ($last ? format_interval(time() - $last) .' '. t('ago') : t('Never'));
$output .= ' <span class="check-manually">'. l(t('Check manually'), 'admin/logs/updates/check') .'</span>';
$output .= "</div>\n";
if (!is_array($data)) {
$output .= '<p>'. $data .'</p>';
return $output;
}
$header = array();
$rows = array();
$notification_level = variable_get('update_notification_threshold', 'all');
foreach ($data as $project) {
switch ($project['status']) {
case UPDATE_CURRENT:
$class = 'ok';
$icon = theme('image', 'misc/watchdog-ok.png');
break;
case UPDATE_NOT_SECURE:
case UPDATE_NOT_CURRENT:
if ($notification_level == 'all'
|| $project['status'] == UPDATE_NOT_SECURE) {
$class = 'error';
$icon = theme('image', 'misc/watchdog-error.png');
break;
}
// Otherwise, deliberate no break and use the warning class/icon.
default:
$class = 'warning';
$icon = theme('image', 'misc/watchdog-warning.png');
break;
}
$row = '<div class="version-status">';
switch ($project['status']) {
case UPDATE_CURRENT:
$row .= t('Up to date');
break;
case UPDATE_NOT_SECURE:
$row .= '<span class="security-error">';
$row .= t('Security update required!');
$row .= '</span>';
break;
case UPDATE_NOT_CURRENT:
$row .= t('Update available');
break;
default:
$row .= check_plain($project['reason']);
break;
}
$row .= '<span class="icon">'. $icon .'</span>';
$row .= "</div>\n";
$row .= '<div class="project">';
if (isset($project['title'])) {
if (isset($project['link'])) {
$row .= l($project['title'], $project['link']);
}
else {
$row .= check_plain($project['title']);
}
}
else {
$row .= check_plain($project['name']);
}
$row .= ' '. check_plain($project['existing_version']);
if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) {
$row .= ' ('. format_date($project['datestamp'], 'custom', 'Y-M-d') .') ';
}
$row .= "</div>\n";
$row .= "<div class=\"versions\">\n";
if (isset($project['recommended'])) {
if ($project['status'] != UPDATE_CURRENT || $project['existing_version'] != $project['recommended']) {
// First, figure out what to recommend.
// If there's only 1 security update and it has the same version we're
// recommending, give it the same CSS class as if it was recommended,
// but don't print out a separate "Recommended" line for this project.
if (!empty($project['security updates']) && count($project['security updates']) == 1 && $project['security updates'][0]['version'] == $project['recommended']) {
$security_class = ' version-recommended version-recommended-strong';
}
else {
$security_class = '';
$version_class = 'version-recommended';
// Apply an extra class if we're displaying both a recommended
// version and anything else for an extra visual hint.
if ($project['recommended'] != $project['latest_version']
|| !empty($project['also'])
|| ($project['install_type'] == 'dev'
&& $project['latest_version'] != $project['dev_version']
&& $project['recommended'] != $project['dev_version'])
|| (isset($project['security updates'][0])
&& $project['recommended'] != $project['security updates'][0])
) {
$version_class .= ' version-recommended-strong';
}
$row .= theme('update_version', $project['releases'][$project['recommended']], t('Recommended version:'), $version_class);
}
// Now, print any security updates.
if (!empty($project['security updates'])) {
foreach ($project['security updates'] as $security_update) {
$row .= theme('update_version', $security_update, t('Security update:'), 'version-security'. $security_class);
}
}
}
if ($project['recommended'] != $project['latest_version']) {
$row .= theme('update_version', $project['releases'][$project['latest_version']], t('Latest version:'), 'version-latest');
}
if ($project['install_type'] == 'dev'
&& $project['status'] != UPDATE_CURRENT
&& $project['recommended'] != $project['dev_version']) {
$row .= theme('update_version', $project['releases'][$project['dev_version']], t('Development version:'), 'version-latest');
}
}
if (isset($project['also'])) {
foreach ($project['also'] as $also) {
$row .= theme('update_version', $project['releases'][$also], t('Also available:'), 'version-also-available');
}
}
$row .= "</div>\n"; // versions div.
$row .= "<div class=\"info\">\n";
if (!empty($project['extra'])) {
$row .= '<div class="extra">' ."\n";
foreach ($project['extra'] as $key => $value) {
$row .= '<div class="'. $value['class'] .'">';
$row .= check_plain($value['label']) .': ';
$row .= theme('placeholder', $value['data']);
$row .= "</div>\n";
}
$row .= "</div>\n"; // extra div.
}
$row .= '<div class="includes">';
sort($project['includes']);
$row .= t('Includes: %includes', array('%includes' => implode(', ', $project['includes'])));
$row .= "</div>\n";
$row .= "</div>\n"; // info div.
if (!isset($rows[$project['project_type']])) {
$rows[$project['project_type']] = array();
}
$rows[$project['project_type']][] = array(
'class' => $class,
'data' => array($row),
);
}
$project_types = array(
'core' => t('Drupal core'),
'module' => t('Modules'),
'theme' => t('Themes'),
);
foreach ($project_types as $type_name => $type_label) {
if (!empty($rows[$type_name])) {
$output .= "\n<h3>". $type_label ."</h3>\n";
$output .= theme('table', $header, $rows[$type_name], array('class' => 'update'));
}
}
drupal_add_css(drupal_get_path('module', 'update') .'/update.css');
return $output;
}
function theme_update_version($version, $tag, $class) {
$output = '';
$output .= '<table class="version '. $class .'">';
$output .= '<tr>';
$output .= '<td class="version-title">'. $tag ."</td>\n";
$output .= '<td class="version-details">';
$output .= l($version['version'], $version['release_link']);
$output .= ' ('. format_date($version['date'], 'custom', 'Y-M-d') .') ';
$output .= "</td>\n";
$output .= '<td class="version-links">';
$links = array();
$links['update-download'] = array(
'title' => t('Download'),
'href' => $version['download_link'],
);
$links['update-release-notes'] = array(
'title' => t('Release notes'),
'href' => $version['release_link'],
);
$output .= theme('links', $links);
$output .= '</td>';
$output .= '</tr>';
$output .= "</table>\n";
return $output;
}
<?php
// $Id$
function update_schema() {
$schema['cache_update'] = drupal_get_schema_unprocessed('system', 'cache');
return $schema;
}
<?php
// $Id$
/**
* @file
* Code required only for the update status settings form.
*/
/**
* Form builder for the update settings tab.
*/
function update_settings() {