Only in /Users/webchick/Sites/7.x/modules/update: tests diff -rup /Users/webchick/Sites/6.x/modules/update/update-rtl.css /Users/webchick/Sites/7.x/modules/update/update-rtl.css --- /Users/webchick/Sites/6.x/modules/update/update-rtl.css 2013-02-19 13:25:56.000000000 -0800 +++ /Users/webchick/Sites/7.x/modules/update/update-rtl.css 2012-12-31 14:20:25.000000000 -0800 @@ -1,3 +1,7 @@ +/** + * @file + * RTL styles used by the Update Manager module. + */ .update .project { padding-right: .25em; Only in /Users/webchick/Sites/7.x/modules/update: update.api.php Only in /Users/webchick/Sites/7.x/modules/update: update.authorize.inc diff -rup /Users/webchick/Sites/6.x/modules/update/update.compare.inc /Users/webchick/Sites/7.x/modules/update/update.compare.inc --- /Users/webchick/Sites/6.x/modules/update/update.compare.inc 2014-01-11 21:40:30.000000000 -0800 +++ /Users/webchick/Sites/7.x/modules/update/update.compare.inc 2012-12-31 14:20:25.000000000 -0800 @@ -6,7 +6,7 @@ */ /** - * Fetch an array of installed and enabled projects. + * Fetches an array of installed and enabled projects. * * This is only responsible for generating an array of projects (taking into * account projects that include more than one module or theme). Other @@ -15,59 +15,114 @@ * that logic is only required when preparing the status report, not for * fetching the available release data. * - * This array is fairly expensive to construct, since it involves a lot of - * disk I/O, so we cache the results into the {cache_update} table using the - * 'update_project_projects' cache ID. However, since this is not the data - * about available updates fetched from the network, it is ok to invalidate it - * somewhat quickly. If we keep this data for very long, site administrators - * are more likely to see incorrect results if they upgrade to a newer version - * of a module or theme but do not visit certain pages that automatically - * clear this cache. + * This array is fairly expensive to construct, since it involves a lot of disk + * I/O, so we cache the results into the {cache_update} table using the + * 'update_project_projects' cache ID. However, since this is not the data about + * available updates fetched from the network, it is acceptable to invalidate it + * somewhat quickly. If we keep this data for very long, site administrators are + * more likely to see incorrect results if they upgrade to a newer version of a + * module or theme but do not visit certain pages that automatically clear this + * cache. + * + * @return + * An associative array of currently enabled projects keyed by the + * machine-readable project short name. Each project contains: + * - name: The machine-readable project short name. + * - info: An array with values from the main .info file for this project. + * - name: The human-readable name of the project. + * - package: The package that the project is grouped under. + * - version: The version of the project. + * - project: The Drupal.org project name. + * - datestamp: The date stamp of the project's main .info file. + * - _info_file_ctime: The maximum file change time for all of the .info + * files included in this project. + * - datestamp: The date stamp when the project was released, if known. + * - includes: An associative array containing all projects included with this + * project, keyed by the machine-readable short name with the human-readable + * name as value. + * - project_type: The type of project. Allowed values are 'module' and + * 'theme'. + * - project_status: This indicates if the project is enabled and will always + * be TRUE, as the function only returns enabled projects. + * - sub_themes: If the project is a theme it contains an associative array of + * all sub-themes. + * - base_themes: If the project is a theme it contains an associative array + * of all base-themes. * * @see update_process_project_info() * @see update_calculate_project_data() * @see update_project_cache() */ function update_get_projects() { - static $projects = array(); + $projects = &drupal_static(__FUNCTION__, array()); if (empty($projects)) { // Retrieve the projects from cache, if present. $projects = update_project_cache('update_project_projects'); if (empty($projects)) { // Still empty, so we have to rebuild the cache. - _update_process_info_list($projects, module_rebuild_cache(), 'module'); - _update_process_info_list($projects, system_theme_data(), 'theme'); + $module_data = system_rebuild_module_data(); + $theme_data = system_rebuild_theme_data(); + _update_process_info_list($projects, $module_data, 'module', TRUE); + _update_process_info_list($projects, $theme_data, 'theme', TRUE); + if (variable_get('update_check_disabled', FALSE)) { + _update_process_info_list($projects, $module_data, 'module', FALSE); + _update_process_info_list($projects, $theme_data, 'theme', FALSE); + } // Allow other modules to alter projects before fetching and comparing. drupal_alter('update_projects', $projects); // Cache the site's project data for at most 1 hour. - _update_cache_set('update_project_projects', $projects, time() + 3600); + _update_cache_set('update_project_projects', $projects, REQUEST_TIME + 3600); } } return $projects; } /** - * Populate an array of project data. + * Populates an array of project data. + * + * This iterates over a list of the installed modules or themes and groups them + * by project and status. A few parts of this function assume that enabled + * modules and themes are always processed first, and if disabled modules or + * themes are being processed (there is a setting to control if disabled code + * should be included or not in the 'Available updates' report), those are only + * processed after $projects has been populated with information about the + * enabled code. Modules and themes set as hidden are always ignored. This + * function also records the latest change time on the .info files for each + * module or theme, which is important data which is used when deciding if the + * cached available update data should be invalidated. + * + * @param $projects + * Reference to the array of project data of what's installed on this site. + * @param $list + * Array of data to process to add the relevant info to the $projects array. + * @param $project_type + * The kind of data in the list. Can be 'module' or 'theme'. + * @param $status + * Boolean that controls what status (enabled or disabled) to process out of + * the $list and add to the $projects array. + * + * @see update_get_projects() */ -function _update_process_info_list(&$projects, $list, $project_type) { +function _update_process_info_list(&$projects, $list, $project_type, $status) { foreach ($list as $file) { // A disabled base theme of an enabled sub-theme still has all of its code // run by the sub-theme, so we include it in our "enabled" projects list. - if (!$file->status && !empty($file->sub_themes)) { + if ($status && !$file->status && !empty($file->sub_themes)) { foreach ($file->sub_themes as $key => $name) { // Build a list of enabled sub-themes. if ($list[$key]->status) { $file->enabled_sub_themes[$key] = $name; } } - // If there are no enabled subthemes, we should ingore this theme and go - // on to the next one. + // If there are no enabled subthemes, we should ignore this base theme + // for the enabled case. If the site is trying to display disabled + // themes, we'll catch it then. if (empty($file->enabled_sub_themes)) { continue; } } - elseif (empty($file->status)) { - // Skip disabled modules or themes. + // Otherwise, just add projects of the proper status to our list. + elseif ($file->status != $status) { continue; } @@ -76,6 +131,11 @@ function _update_process_info_list(&$pro continue; } + // Skip if it's a hidden module or theme. + if (!empty($file->info['hidden'])) { + continue; + } + // If the .info doesn't define the 'project', try to figure it out. if (!isset($file->info['project'])) { $file->info['project'] = update_get_project_name($file); @@ -94,7 +154,7 @@ function _update_process_info_list(&$pro // which is left alone by tar and correctly set to the time the .info file // was unpacked. if (!isset($file->info['_info_file_ctime'])) { - $info_filename = dirname($file->filename) .'/'. $file->name .'.info'; + $info_filename = dirname($file->uri) . '/' . $file->name . '.info'; $file->info['_info_file_ctime'] = filectime($info_filename); } @@ -104,6 +164,22 @@ function _update_process_info_list(&$pro $project_name = $file->info['project']; + // Figure out what project type we're going to use to display this module + // or theme. If the project name is 'drupal', we don't want it to show up + // under the usual "Modules" section, we put it at a special "Drupal Core" + // section at the top of the report. + if ($project_name == 'drupal') { + $project_display_type = 'core'; + } + else { + $project_display_type = $project_type; + } + if (empty($status) && empty($file->enabled_sub_themes)) { + // If we're processing disabled modules or themes, append a suffix. + // However, we don't do this to a a base theme with enabled + // subthemes, since we treat that case as if it is enabled. + $project_display_type .= '-disabled'; + } // Add a list of sub-themes that "depend on" the project and a list of base // themes that are "required by" the project. if ($project_name == 'drupal') { @@ -117,7 +193,6 @@ function _update_process_info_list(&$pro // Add list of base themes. $base_themes = !empty($file->base_themes) ? $file->base_themes : array(); } - if (!isset($projects[$project_name])) { // Only process this if we haven't done this project, since a single // project can have multiple modules or themes. @@ -128,24 +203,46 @@ function _update_process_info_list(&$pro 'info' => update_filter_project_info($file->info), 'datestamp' => $file->info['datestamp'], 'includes' => array($file->name => $file->info['name']), - 'project_type' => $project_name == 'drupal' ? 'core' : $project_type, + 'project_type' => $project_display_type, + 'project_status' => $status, 'sub_themes' => $sub_themes, 'base_themes' => $base_themes, ); } - else { + elseif ($projects[$project_name]['project_type'] == $project_display_type) { + // Only add the file we're processing to the 'includes' array for this + // project if it is of the same type and status (which is encoded in the + // $project_display_type). This prevents listing all the disabled + // modules included with an enabled project if we happen to be checking + // for disabled modules, too. $projects[$project_name]['includes'][$file->name] = $file->info['name']; $projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']); $projects[$project_name]['datestamp'] = max($projects[$project_name]['datestamp'], $file->info['datestamp']); - $projects[$project_name]['sub_themes'] = array_merge($projects[$project_name]['sub_themes'], $sub_themes); - $projects[$project_name]['base_themes'] = array_merge($projects[$project_name]['base_themes'], $base_themes); + if (!empty($sub_themes)) { + $projects[$project_name]['sub_themes'] += $sub_themes; + } + if (!empty($base_themes)) { + $projects[$project_name]['base_themes'] += $base_themes; + } + } + elseif (empty($status)) { + // If we have a project_name that matches, but the project_display_type + // does not, it means we're processing a disabled module or theme that + // belongs to a project that has some enabled code. In this case, we add + // the disabled thing into a separate array for separate display. + $projects[$project_name]['disabled'][$file->name] = $file->info['name']; } } } /** - * Given a $file object (as returned by system_get_files_database()), figure - * out what project it belongs to. + * Determines what project a given file object belongs to. + * + * @param $file + * A file object as returned by system_get_files_database(). + * + * @return + * The canonical project short name. * * @see system_get_files_database() */ @@ -154,19 +251,16 @@ function update_get_project_name($file) if (isset($file->info['project'])) { $project_name = $file->info['project']; } - elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core -') !== FALSE)) { - $project_name = 'drupal'; - } - elseif (in_array($file->name, array('bluemarine', 'chameleon', 'garland', 'marvin', 'minnelli', 'pushbutton'))) { - // Unfortunately, there's no way to tell if a theme is part of core, - // so we must hard-code a list here. + elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core') === 0)) { $project_name = 'drupal'; } return $project_name; } /** - * Process the list of projects on the system to figure out the currently + * Determines version and type information for currently installed projects. + * + * Processes the list of projects on the system to figure out the currently * installed versions, and other information that is required before we can * compare against the available releases to produce the status report. * @@ -215,64 +309,7 @@ function update_process_project_info(&$p } /** - * Given the installed projects and the available release data retrieved from - * remote servers, calculate the current status. - * - * This function is the heart of the update status feature. It iterates over - * every currently installed project. For each one, it first checks if the - * project has been flagged with a special status like "unsupported" or - * "insecure", or if the project node itself has been unpublished. In any of - * those cases, the project is marked with an error and the next project is - * considered. - * - * If the project itself is valid, the function decides what major release - * series to consider. The project defines what the currently supported major - * versions are for each version of core, so the first step is to make sure - * the current version is still supported. If so, that's the target version. - * If the current version is unsupported, the project maintainer's recommended - * major version is used. There's also a check to make sure that this function - * never recommends an earlier release than the currently installed major - * version. - * - * Given a target major version, it scans the available releases looking for - * the specific release to recommend (avoiding beta releases and development - * snapshots if possible). This is complicated to describe, but an example - * will help clarify. For the target major version, find the highest patch - * level. If there is a release at that patch level with no extra ("beta", - * etc), then we recommend the release at that patch level with the most - * recent release date. If every release at that patch level has extra (only - * betas), then recommend the latest release from the previous patch - * level. For example: - * - * 1.6-bugfix <-- recommended version because 1.6 already exists. - * 1.6 - * - * or - * - * 1.6-beta - * 1.5 <-- recommended version because no 1.6 exists. - * 1.4 - * - * It also looks for the latest release from the same major version, even a - * beta release, to display to the user as the "Latest version" option. - * Additionally, it finds the latest official release from any higher major - * versions that have been released to provide a set of "Also available" - * options. - * - * Finally, and most importantly, it keeps scanning the release history until - * it gets to the currently installed release, searching for anything marked - * as a security update. If any security updates have been found between the - * recommended release and the installed version, all of the releases that - * included a security fix are recorded so that the site administrator can be - * warned their site is insecure, and links pointing to the release notes for - * each security update can be included (which, in turn, will link to the - * official security announcements for each vulnerability). - * - * This function relies on the fact that the .xml release history data comes - * sorted based on major version and patch level, then finally by release date - * if there are multiple releases such as betas from the same major.patch - * version (e.g. 5.x-1.5-beta1, 5.x-1.5-beta2, and 5.x-1.5). Development - * snapshots for a given major version are always listed last. + * Calculates the current update status of all projects on the site. * * The results of this function are expensive to compute, especially on sites * with lots of modules or themes, since it involves a lot of comparisons and @@ -280,12 +317,15 @@ function update_process_project_info(&$p * table using the 'update_project_data' cache ID. However, since this is not * the data about available updates fetched from the network, it is ok to * invalidate it somewhat quickly. If we keep this data for very long, site - * administrators are more likely to see incorrect results if they upgrade to - * a newer version of a module or theme but do not visit certain pages that + * administrators are more likely to see incorrect results if they upgrade to a + * newer version of a module or theme but do not visit certain pages that * automatically clear this cache. * - * @param $available - * Array of data about available project releases. + * @param array $available + * Data about available project releases. + * + * @return + * An array of installed projects with current update status information. * * @see update_get_available() * @see update_get_projects() @@ -304,335 +344,421 @@ function update_calculate_project_data($ update_process_project_info($projects); foreach ($projects as $project => $project_info) { if (isset($available[$project])) { + update_calculate_project_update_status($project, $projects[$project], $available[$project]); + } + else { + $projects[$project]['status'] = UPDATE_UNKNOWN; + $projects[$project]['reason'] = t('No available releases found'); + } + } + // Give other modules a chance to alter the status (for example, to allow a + // contrib module to provide fine-grained settings to ignore specific + // projects or releases). + drupal_alter('update_status', $projects); - // If the project status is marked as something bad, there's nothing - // else to consider. - if (isset($available[$project]['project_status'])) { - switch ($available[$project]['project_status']) { - case 'insecure': - $projects[$project]['status'] = UPDATE_NOT_SECURE; - if (empty($projects[$project]['extra'])) { - $projects[$project]['extra'] = array(); - } - $projects[$project]['extra'][] = array( - 'class' => 'project-not-secure', - 'label' => t('Project not secure'), - 'data' => t('This project has been labeled insecure by the Drupal security team, and is no longer available for download. Immediately disabling everything included by this project is strongly recommended!'), - ); - break; - case 'unpublished': - case 'revoked': - $projects[$project]['status'] = UPDATE_REVOKED; - if (empty($projects[$project]['extra'])) { - $projects[$project]['extra'] = array(); - } - $projects[$project]['extra'][] = array( - 'class' => 'project-revoked', - 'label' => t('Project revoked'), - 'data' => t('This project has been revoked, and is no longer available for download. Disabling everything included by this project is strongly recommended!'), - ); - break; - case 'unsupported': - $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; - if (empty($projects[$project]['extra'])) { - $projects[$project]['extra'] = array(); - } - $projects[$project]['extra'][] = array( - 'class' => 'project-not-supported', - 'label' => t('Project not supported'), - 'data' => t('This project is no longer supported, and is no longer available for download. Disabling everything included by this project is strongly recommended!'), - ); - break; - case 'not-fetched': - $projects[$project]['status'] = UPDATE_NOT_FETCHED; - $projects[$project]['reason'] = t('Failed to fetch available update data'); - break; - - default: - // Assume anything else (e.g. 'published') is valid and we should - // perform the rest of the logic in this function. - break; - } - } + // Cache the site's update status for at most 1 hour. + _update_cache_set('update_project_data', $projects, REQUEST_TIME + 3600); + return $projects; +} - if (!empty($projects[$project]['status'])) { - // We already know the status for this project, so there's nothing - // else to compute. Just record everything else we fetched from the - // XML file into our projects array and move to the next project. - $projects[$project] += $available[$project]; - continue; - } +/** + * Calculates the current update status of a specific project. + * + * This function is the heart of the update status feature. For each project it + * is invoked with, it first checks if the project has been flagged with a + * special status like "unsupported" or "insecure", or if the project node + * itself has been unpublished. In any of those cases, the project is marked + * with an error and the next project is considered. + * + * If the project itself is valid, the function decides what major release + * series to consider. The project defines what the currently supported major + * versions are for each version of core, so the first step is to make sure the + * current version is still supported. If so, that's the target version. If the + * current version is unsupported, the project maintainer's recommended major + * version is used. There's also a check to make sure that this function never + * recommends an earlier release than the currently installed major version. + * + * Given a target major version, the available releases are scanned looking for + * the specific release to recommend (avoiding beta releases and development + * snapshots if possible). For the target major version, the highest patch level + * is found. If there is a release at that patch level with no extra ("beta", + * etc.), then the release at that patch level with the most recent release date + * is recommended. If every release at that patch level has extra (only betas), + * then the latest release from the previous patch level is recommended. For + * example: + * + * - 1.6-bugfix <-- recommended version because 1.6 already exists. + * - 1.6 + * + * or + * + * - 1.6-beta + * - 1.5 <-- recommended version because no 1.6 exists. + * - 1.4 + * + * Also, the latest release from the same major version is looked for, even beta + * releases, to display to the user as the "Latest version" option. + * Additionally, the latest official release from any higher major versions that + * have been released is searched for to provide a set of "Also available" + * options. + * + * Finally, and most importantly, the release history continues to be scanned + * until the currently installed release is reached, searching for anything + * marked as a security update. If any security updates have been found between + * the recommended release and the installed version, all of the releases that + * included a security fix are recorded so that the site administrator can be + * warned their site is insecure, and links pointing to the release notes for + * each security update can be included (which, in turn, will link to the + * official security announcements for each vulnerability). + * + * This function relies on the fact that the .xml release history data comes + * sorted based on major version and patch level, then finally by release date + * if there are multiple releases such as betas from the same major.patch + * version (e.g., 5.x-1.5-beta1, 5.x-1.5-beta2, and 5.x-1.5). Development + * snapshots for a given major version are always listed last. + * + * @param $project + * An array containing information about a specific project. + * @param $project_data + * An array containing information about a specific project. + * @param $available + * Data about available project releases of a specific project. + */ +function update_calculate_project_update_status($project, &$project_data, $available) { + foreach (array('title', 'link') as $attribute) { + if (!isset($project_data[$attribute]) && isset($available[$attribute])) { + $project_data[$attribute] = $available[$attribute]; + } + } + + // If the project status is marked as something bad, there's nothing else + // to consider. + if (isset($available['project_status'])) { + switch ($available['project_status']) { + case 'insecure': + $project_data['status'] = UPDATE_NOT_SECURE; + if (empty($project_data['extra'])) { + $project_data['extra'] = array(); + } + $project_data['extra'][] = array( + 'class' => array('project-not-secure'), + 'label' => t('Project not secure'), + 'data' => t('This project has been labeled insecure by the Drupal security team, and is no longer available for download. Immediately disabling everything included by this project is strongly recommended!'), + ); + break; + case 'unpublished': + case 'revoked': + $project_data['status'] = UPDATE_REVOKED; + if (empty($project_data['extra'])) { + $project_data['extra'] = array(); + } + $project_data['extra'][] = array( + 'class' => array('project-revoked'), + 'label' => t('Project revoked'), + 'data' => t('This project has been revoked, and is no longer available for download. Disabling everything included by this project is strongly recommended!'), + ); + break; + case 'unsupported': + $project_data['status'] = UPDATE_NOT_SUPPORTED; + if (empty($project_data['extra'])) { + $project_data['extra'] = array(); + } + $project_data['extra'][] = array( + 'class' => array('project-not-supported'), + 'label' => t('Project not supported'), + 'data' => t('This project is no longer supported, and is no longer available for download. Disabling everything included by this project is strongly recommended!'), + ); + break; + case 'not-fetched': + $project_data['status'] = UPDATE_NOT_FETCHED; + $project_data['reason'] = t('Failed to get available update data.'); + break; + + default: + // Assume anything else (e.g. 'published') is valid and we should + // perform the rest of the logic in this function. + break; + } + } + + if (!empty($project_data['status'])) { + // We already know the status for this project, so there's nothing else to + // compute. Record the project status into $project_data and we're done. + $project_data['project_status'] = $available['project_status']; + return; + } + + // Figure out the target major version. + $existing_major = $project_data['existing_major']; + $supported_majors = array(); + if (isset($available['supported_majors'])) { + $supported_majors = explode(',', $available['supported_majors']); + } + elseif (isset($available['default_major'])) { + // Older release history XML file without supported or recommended. + $supported_majors[] = $available['default_major']; + } + + if (in_array($existing_major, $supported_majors)) { + // Still supported, stay at the current major version. + $target_major = $existing_major; + } + elseif (isset($available['recommended_major'])) { + // Since 'recommended_major' is defined, we know this is the new XML + // format. Therefore, we know the current release is unsupported since + // its major version was not in the 'supported_majors' list. We should + // find the best release from the recommended major version. + $target_major = $available['recommended_major']; + $project_data['status'] = UPDATE_NOT_SUPPORTED; + } + elseif (isset($available['default_major'])) { + // Older release history XML file without recommended, so recommend + // the currently defined "default_major" version. + $target_major = $available['default_major']; + } + else { + // Malformed XML file? Stick with the current version. + $target_major = $existing_major; + } - // Figure out the target major version. - $existing_major = $project_info['existing_major']; - $supported_majors = array(); - if (isset($available[$project]['supported_majors'])) { - $supported_majors = explode(',', $available[$project]['supported_majors']); - } - elseif (isset($available[$project]['default_major'])) { - // Older release history XML file without supported or recommended. - $supported_majors[] = $available[$project]['default_major']; - } - - if (in_array($existing_major, $supported_majors)) { - // Still supported, stay at the current major version. - $target_major = $existing_major; - } - elseif (isset($available[$project]['recommended_major'])) { - // Since 'recommended_major' is defined, we know this is the new XML - // format. Therefore, we know the current release is unsupported since - // its major version was not in the 'supported_majors' list. We should - // find the best release from the recommended major version. - $target_major = $available[$project]['recommended_major']; - $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; - } - elseif (isset($available[$project]['default_major'])) { - // Older release history XML file without recommended, so recommend - // the currently defined "default_major" version. - $target_major = $available[$project]['default_major']; - } - else { - // Malformed XML file? Stick with the current version. - $target_major = $existing_major; + // Make sure we never tell the admin to downgrade. If we recommended an + // earlier version than the one they're running, they'd face an + // impossible data migration problem, since Drupal never supports a DB + // downgrade path. In the unfortunate case that what they're running is + // unsupported, and there's nothing newer for them to upgrade to, we + // can't print out a "Recommended version", but just have to tell them + // what they have is unsupported and let them figure it out. + $target_major = max($existing_major, $target_major); + + $release_patch_changed = ''; + $patch = ''; + + // If the project is marked as UPDATE_FETCH_PENDING, it means that the + // data we currently have (if any) is stale, and we've got a task queued + // up to (re)fetch the data. In that case, we mark it as such, merge in + // whatever data we have (e.g. project title and link), and move on. + if (!empty($available['fetch_status']) && $available['fetch_status'] == UPDATE_FETCH_PENDING) { + $project_data['status'] = UPDATE_FETCH_PENDING; + $project_data['reason'] = t('No available update data'); + $project_data['fetch_status'] = $available['fetch_status']; + return; + } + + // Defend ourselves from XML history files that contain no releases. + if (empty($available['releases'])) { + $project_data['status'] = UPDATE_UNKNOWN; + $project_data['reason'] = t('No available releases found'); + return; + } + foreach ($available['releases'] as $version => $release) { + // First, if this is the existing release, check a few conditions. + if ($project_data['existing_version'] === $version) { + if (isset($release['terms']['Release type']) && + in_array('Insecure', $release['terms']['Release type'])) { + $project_data['status'] = UPDATE_NOT_SECURE; + } + elseif ($release['status'] == 'unpublished') { + $project_data['status'] = UPDATE_REVOKED; + if (empty($project_data['extra'])) { + $project_data['extra'] = array(); + } + $project_data['extra'][] = array( + 'class' => array('release-revoked'), + 'label' => t('Release revoked'), + 'data' => t('Your currently installed release has been revoked, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), + ); + } + elseif (isset($release['terms']['Release type']) && + in_array('Unsupported', $release['terms']['Release type'])) { + $project_data['status'] = UPDATE_NOT_SUPPORTED; + if (empty($project_data['extra'])) { + $project_data['extra'] = array(); + } + $project_data['extra'][] = array( + 'class' => array('release-not-supported'), + 'label' => t('Release not supported'), + 'data' => t('Your currently installed release is now unsupported, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), + ); + } + } + + // Otherwise, ignore unpublished, insecure, or unsupported releases. + if ($release['status'] == 'unpublished' || + (isset($release['terms']['Release type']) && + (in_array('Insecure', $release['terms']['Release type']) || + in_array('Unsupported', $release['terms']['Release type'])))) { + continue; + } + + // See if this is a higher major version than our target and yet still + // supported. If so, record it as an "Also available" release. + // Note: some projects have a HEAD release from CVS days, which could + // be one of those being compared. They would not have version_major + // set, so we must call isset first. + if (isset($release['version_major']) && $release['version_major'] > $target_major) { + if (in_array($release['version_major'], $supported_majors)) { + if (!isset($project_data['also'])) { + $project_data['also'] = array(); + } + if (!isset($project_data['also'][$release['version_major']])) { + $project_data['also'][$release['version_major']] = $version; + $project_data['releases'][$version] = $release; + } + } + // Otherwise, this release can't matter to us, since it's neither + // from the release series we're currently using nor the recommended + // release. We don't even care about security updates for this + // branch, since if a project maintainer puts out a security release + // at a higher major version and not at the lower major version, + // they must remove the lower version from the supported major + // versions at the same time, in which case we won't hit this code. + continue; + } + + // Look for the 'latest version' if we haven't found it yet. Latest is + // defined as the most recent version for the target major version. + if (!isset($project_data['latest_version']) + && $release['version_major'] == $target_major) { + $project_data['latest_version'] = $version; + $project_data['releases'][$version] = $release; + } + + // Look for the development snapshot release for this branch. + if (!isset($project_data['dev_version']) + && $release['version_major'] == $target_major + && isset($release['version_extra']) + && $release['version_extra'] == 'dev') { + $project_data['dev_version'] = $version; + $project_data['releases'][$version] = $release; + } + + // Look for the 'recommended' version if we haven't found it yet (see + // phpdoc at the top of this function for the definition). + if (!isset($project_data['recommended']) + && $release['version_major'] == $target_major + && isset($release['version_patch'])) { + if ($patch != $release['version_patch']) { + $patch = $release['version_patch']; + $release_patch_changed = $release; + } + if (empty($release['version_extra']) && $patch == $release['version_patch']) { + $project_data['recommended'] = $release_patch_changed['version']; + $project_data['releases'][$release_patch_changed['version']] = $release_patch_changed; } + } - // Make sure we never tell the admin to downgrade. If we recommended an - // earlier version than the one they're running, they'd face an - // impossible data migration problem, since Drupal never supports a DB - // downgrade path. In the unfortunate case that what they're running is - // unsupported, and there's nothing newer for them to upgrade to, we - // can't print out a "Recommended version", but just have to tell them - // what they have is unsupported and let them figure it out. - $target_major = max($existing_major, $target_major); - - $version_patch_changed = ''; - $patch = ''; - - // Defend ourselves from XML history files that contain no releases. - if (empty($available[$project]['releases'])) { - $projects[$project]['status'] = UPDATE_UNKNOWN; - $projects[$project]['reason'] = t('No available releases found'); + // Stop searching once we hit the currently installed version. + if ($project_data['existing_version'] === $version) { + break; + } + + // If we're running a dev snapshot and have a timestamp, stop + // searching for security updates once we hit an official release + // older than what we've got. Allow 100 seconds of leeway to handle + // differences between the datestamp in the .info file and the + // timestamp of the tarball itself (which are usually off by 1 or 2 + // seconds) so that we don't flag that as a new release. + if ($project_data['install_type'] == 'dev') { + if (empty($project_data['datestamp'])) { + // We don't have current timestamp info, so we can't know. continue; } - foreach ($available[$project]['releases'] as $version => $release) { - // First, if this is the existing release, check a few conditions. - if ($projects[$project]['existing_version'] === $version) { - if (isset($release['terms']['Release type']) && - in_array('Insecure', $release['terms']['Release type'])) { - $projects[$project]['status'] = UPDATE_NOT_SECURE; - } - elseif ($release['status'] == 'unpublished') { - $projects[$project]['status'] = UPDATE_REVOKED; - if (empty($projects[$project]['extra'])) { - $projects[$project]['extra'] = array(); - } - $projects[$project]['extra'][] = array( - 'class' => 'release-revoked', - 'label' => t('Release revoked'), - 'data' => t('Your currently installed release has been revoked, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), - ); - } - elseif (isset($release['terms']['Release type']) && - in_array('Unsupported', $release['terms']['Release type'])) { - $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; - if (empty($projects[$project]['extra'])) { - $projects[$project]['extra'] = array(); - } - $projects[$project]['extra'][] = array( - 'class' => 'release-not-supported', - 'label' => t('Release not supported'), - 'data' => t('Your currently installed release is now unsupported, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), - ); - } - } - - // Otherwise, ignore unpublished, insecure, or unsupported releases. - if ($release['status'] == 'unpublished' || - (isset($release['terms']['Release type']) && - (in_array('Insecure', $release['terms']['Release type']) || - in_array('Unsupported', $release['terms']['Release type'])))) { - continue; - } + elseif (isset($release['date']) && ($project_data['datestamp'] + 100 > $release['date'])) { + // We're newer than this, so we can skip it. + continue; + } + } - // See if this is a higher major version than our target and yet still - // supported. If so, record it as an "Also available" release. - if ($release['version_major'] > $target_major) { - if (in_array($release['version_major'], $supported_majors)) { - if (!isset($available[$project]['also'])) { - $available[$project]['also'] = array(); - } - if (!isset($available[$project]['also'][$release['version_major']])) { - $available[$project]['also'][$release['version_major']] = $version; - } - } - // Otherwise, this release can't matter to us, since it's neither - // from the release series we're currently using nor the recommended - // release. We don't even care about security updates for this - // branch, since if a project maintainer puts out a security release - // at a higher major version and not at the lower major version, - // they must remove the lower version from the supported major - // versions at the same time, in which case we won't hit this code. - continue; - } + // See if this release is a security update. + if (isset($release['terms']['Release type']) + && in_array('Security update', $release['terms']['Release type'])) { + $project_data['security updates'][] = $release; + } + } - // Look for the 'latest version' if we haven't found it yet. Latest is - // defined as the most recent version for the target major version. - if (!isset($available[$project]['latest_version']) - && $release['version_major'] == $target_major) { - $available[$project]['latest_version'] = $version; - } + // If we were unable to find a recommended version, then make the latest + // version the recommended version if possible. + if (!isset($project_data['recommended']) && isset($project_data['latest_version'])) { + $project_data['recommended'] = $project_data['latest_version']; + } - // Look for the development snapshot release for this branch. - if (!isset($available[$project]['dev_version']) - && $release['version_major'] == $target_major - && isset($release['version_extra']) - && $release['version_extra'] == 'dev') { - $available[$project]['dev_version'] = $version; - } + // + // Check to see if we need an update or not. + // - // Look for the 'recommended' version if we haven't found it yet (see - // phpdoc at the top of this function for the definition). - if (!isset($available[$project]['recommended']) - && $release['version_major'] == $target_major - && isset($release['version_patch'])) { - if ($patch != $release['version_patch']) { - $patch = $release['version_patch']; - $version_patch_changed = $release['version']; - } - if (empty($release['version_extra']) && $patch == $release['version_patch']) { - $available[$project]['recommended'] = $version_patch_changed; - } - } + if (!empty($project_data['security updates'])) { + // If we found security updates, that always trumps any other status. + $project_data['status'] = UPDATE_NOT_SECURE; + } - // Stop searching once we hit the currently installed version. - if ($projects[$project]['existing_version'] === $version) { - break; - } + if (isset($project_data['status'])) { + // If we already know the status, we're done. + return; + } - // If we're running a dev snapshot and have a timestamp, stop - // searching for security updates once we hit an official release - // older than what we've got. Allow 100 seconds of leeway to handle - // differences between the datestamp in the .info file and the - // timestamp of the tarball itself (which are usually off by 1 or 2 - // seconds) so that we don't flag that as a new release. - if ($projects[$project]['install_type'] == 'dev') { - if (empty($projects[$project]['datestamp'])) { - // We don't have current timestamp info, so we can't know. - continue; - } - elseif (isset($release['date']) && ($projects[$project]['datestamp'] + 100 > $release['date'])) { - // We're newer than this, so we can skip it. - continue; - } - } + // If we don't know what to recommend, there's nothing we can report. + // Bail out early. + if (!isset($project_data['recommended'])) { + $project_data['status'] = UPDATE_UNKNOWN; + $project_data['reason'] = t('No available releases found'); + return; + } - // See if this release is a security update. - if (isset($release['terms']['Release type']) - && in_array('Security update', $release['terms']['Release type'])) { - $projects[$project]['security updates'][] = $release; - } - } + // If we're running a dev snapshot, compare the date of the dev snapshot + // with the latest official version, and record the absolute latest in + // 'latest_dev' so we can correctly decide if there's a newer release + // than our current snapshot. + if ($project_data['install_type'] == 'dev') { + if (isset($project_data['dev_version']) && $available['releases'][$project_data['dev_version']]['date'] > $available['releases'][$project_data['latest_version']]['date']) { + $project_data['latest_dev'] = $project_data['dev_version']; + } + else { + $project_data['latest_dev'] = $project_data['latest_version']; + } + } - // If we were unable to find a recommended version, then make the latest - // version the recommended version if possible. - if (!isset($available[$project]['recommended']) && isset($available[$project]['latest_version'])) { - $available[$project]['recommended'] = $available[$project]['latest_version']; + // Figure out the status, based on what we've seen and the install type. + switch ($project_data['install_type']) { + case 'official': + if ($project_data['existing_version'] === $project_data['recommended'] || $project_data['existing_version'] === $project_data['latest_version']) { + $project_data['status'] = UPDATE_CURRENT; } - - // Stash the info about available releases into our $projects array. - $projects[$project] += $available[$project]; - - // - // Check to see if we need an update or not. - // - - if (!empty($projects[$project]['security updates'])) { - // If we found security updates, that always trumps any other status. - $projects[$project]['status'] = UPDATE_NOT_SECURE; + else { + $project_data['status'] = UPDATE_NOT_CURRENT; } + break; - if (isset($projects[$project]['status'])) { - // If we already know the status, we're done. - continue; + case 'dev': + $latest = $available['releases'][$project_data['latest_dev']]; + if (empty($project_data['datestamp'])) { + $project_data['status'] = UPDATE_NOT_CHECKED; + $project_data['reason'] = t('Unknown release date'); } - - // If we don't know what to recommend, there's nothing we can report. - // Bail out early. - if (!isset($projects[$project]['recommended'])) { - $projects[$project]['status'] = UPDATE_UNKNOWN; - $projects[$project]['reason'] = t('No available releases found'); - continue; + elseif (($project_data['datestamp'] + 100 > $latest['date'])) { + $project_data['status'] = UPDATE_CURRENT; } - - // If we're running a dev snapshot, compare the date of the dev snapshot - // with the latest official version, and record the absolute latest in - // 'latest_dev' so we can correctly decide if there's a newer release - // than our current snapshot. - if ($projects[$project]['install_type'] == 'dev') { - if (isset($available[$project]['dev_version']) && $available[$project]['releases'][$available[$project]['dev_version']]['date'] > $available[$project]['releases'][$available[$project]['latest_version']]['date']) { - $projects[$project]['latest_dev'] = $available[$project]['dev_version']; - } - else { - $projects[$project]['latest_dev'] = $available[$project]['latest_version']; - } + else { + $project_data['status'] = UPDATE_NOT_CURRENT; } + break; - // Figure out the status, based on what we've seen and the install type. - switch ($projects[$project]['install_type']) { - case 'official': - if ($projects[$project]['existing_version'] === $projects[$project]['recommended'] || $projects[$project]['existing_version'] === $projects[$project]['latest_version']) { - $projects[$project]['status'] = UPDATE_CURRENT; - } - else { - $projects[$project]['status'] = UPDATE_NOT_CURRENT; - } - break; - - case 'dev': - $latest = $available[$project]['releases'][$projects[$project]['latest_dev']]; - if (empty($projects[$project]['datestamp'])) { - $projects[$project]['status'] = UPDATE_NOT_CHECKED; - $projects[$project]['reason'] = t('Unknown release date'); - } - elseif (($projects[$project]['datestamp'] + 100 > $latest['date'])) { - $projects[$project]['status'] = UPDATE_CURRENT; - } - else { - $projects[$project]['status'] = UPDATE_NOT_CURRENT; - } - break; - - default: - $projects[$project]['status'] = UPDATE_UNKNOWN; - $projects[$project]['reason'] = t('Invalid info'); - } - } - else { - $projects[$project]['status'] = UPDATE_UNKNOWN; - $projects[$project]['reason'] = t('No available releases found'); - } + default: + $project_data['status'] = UPDATE_UNKNOWN; + $project_data['reason'] = t('Invalid info'); } - // Give other modules a chance to alter the status (for example, to allow a - // contrib module to provide fine-grained settings to ignore specific - // projects or releases). - drupal_alter('update_status', $projects); - - // Cache the site's update status for at most 1 hour. - _update_cache_set('update_project_data', $projects, time() + 3600); - return $projects; } /** - * Retrieve data from {cache_update} or empty the cache when necessary. + * Retrieves data from {cache_update} or empties the cache when necessary. * * Two very expensive arrays computed by this module are the list of all - * installed modules and themes (and .info data, project associations, etc), - * and the current status of the site relative to the currently available - * releases. These two arrays are cached in the {cache_update} table and used - * whenever possible. The cache is cleared whenever the administrator visits - * the status report, available updates report, or the module or theme - * administration pages, since we should always recompute the most current - * values on any of those pages. + * installed modules and themes (and .info data, project associations, etc), and + * the current status of the site relative to the currently available releases. + * These two arrays are cached in the {cache_update} table and used whenever + * possible. The cache is cleared whenever the administrator visits the status + * report, available updates report, or the module or theme administration + * pages, since we should always recompute the most current values on any of + * those pages. * * Note: while both of these arrays are expensive to compute (in terms of disk * I/O and some fairly heavy CPU processing), neither of these is the actual @@ -642,27 +768,37 @@ function update_calculate_project_data($ * hour and never get invalidated just by visiting a page on the site. * * @param $cid - * The cache id of data to return from the cache. Valid options are + * The cache ID of data to return from the cache. Valid options are * 'update_project_data' and 'update_project_projects'. * * @return * The cached value of the $projects array generated by - * update_calculate_project_data() or update_get_projects(), or an empty - * array when the cache is cleared. + * update_calculate_project_data() or update_get_projects(), or an empty array + * when the cache is cleared. */ function update_project_cache($cid) { $projects = array(); - // On certain paths, we should clear the cache and recompute the projects or + // On certain paths, we should clear the cache and recompute the projects for // update status of the site to avoid presenting stale information. $q = $_GET['q']; - $paths = array('admin/build/modules', 'admin/build/themes', 'admin/reports', 'admin/reports/updates', 'admin/reports/status', 'admin/reports/updates/check'); + $paths = array( + 'admin/modules', + 'admin/modules/update', + 'admin/appearance', + 'admin/appearance/update', + 'admin/reports', + 'admin/reports/updates', + 'admin/reports/updates/update', + 'admin/reports/status', + 'admin/reports/updates/check', + ); if (in_array($q, $paths)) { _update_cache_clear($cid); } else { $cache = _update_cache_get($cid); - if (!empty($cache->data) && $cache->expire > time()) { + if (!empty($cache->data) && $cache->expire > REQUEST_TIME) { $projects = $cache->data; } } @@ -670,13 +806,13 @@ function update_project_cache($cid) { } /** - * Filter the project .info data to only save attributes we need. + * Filters the project .info data to only save attributes we need. * * @param array $info * Array of .info file data as returned by drupal_parse_info_file(). * * @return - * Array of .info file data we need for the Update manager. + * Array of .info file data we need for the update manager. * * @see _update_process_info_list() */ @@ -691,11 +827,5 @@ function update_filter_project_info($inf 'project status url', 'version', ); - $whitelist = array_flip($whitelist); - foreach ($info as $key => $value) { - if (!isset($whitelist[$key])) { - unset($info[$key]); - } - } - return $info; + return array_intersect_key($info, drupal_map_assoc($whitelist)); } diff -rup /Users/webchick/Sites/6.x/modules/update/update.css /Users/webchick/Sites/7.x/modules/update/update.css --- /Users/webchick/Sites/6.x/modules/update/update.css 2014-01-11 21:40:30.000000000 -0800 +++ /Users/webchick/Sites/7.x/modules/update/update.css 2012-12-31 14:20:25.000000000 -0800 @@ -1,3 +1,7 @@ +/** + * @file + * Styles used by the Update Manager module. + */ .update .project { font-weight: bold; @@ -26,6 +30,11 @@ padding: 1em 1em .25em 1em; } +.update tr.even, +.update tr.odd { + border: none; +} + .update tr td { border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; @@ -51,7 +60,8 @@ background: #ffe; } -.current-version, .new-version { +.current-version, +.new-version { direction: ltr; /* Note: version numbers should always be LTR. */ } @@ -63,6 +73,7 @@ table.update, .update table.version { width: 100%; margin-top: .5em; + border: none; } .update table.version tbody { @@ -75,6 +86,7 @@ table.update, padding: 0; margin: 0; border: none; + background: none; } .update table.version .version-title { @@ -107,3 +119,17 @@ table.update, .update .check-manually { padding-left: 1em; /* LTR */ } + +.update-major-version-warning { + color: #ff0000; +} + +table tbody tr.update-security, +table tbody tr.update-unsupported { + background: #fcc; +} + +th.update-project-name { + width: 50%; +} + diff -rup /Users/webchick/Sites/6.x/modules/update/update.fetch.inc /Users/webchick/Sites/7.x/modules/update/update.fetch.inc --- /Users/webchick/Sites/6.x/modules/update/update.fetch.inc 2014-01-11 21:40:30.000000000 -0800 +++ /Users/webchick/Sites/7.x/modules/update/update.fetch.inc 2013-12-09 23:57:55.000000000 -0800 @@ -6,24 +6,195 @@ */ /** - * Callback to manually check the update status without cron. + * Page callback: Checks for updates and displays the update status report. + * + * Manually checks the update status without the use of cron. + * + * @see update_menu() */ function update_manual_status() { - if (_update_refresh()) { - drupal_set_message(t('Attempted to fetch information about all available new releases and updates.')); + _update_refresh(); + $batch = array( + 'operations' => array( + array('update_fetch_data_batch', array()), + ), + 'finished' => 'update_fetch_data_finished', + 'title' => t('Checking available update data'), + 'progress_message' => t('Trying to check available update data ...'), + 'error_message' => t('Error checking available update data.'), + 'file' => drupal_get_path('module', 'update') . '/update.fetch.inc', + ); + batch_set($batch); + batch_process('admin/reports/updates'); +} + +/** + * Batch callback: Processes a step in batch for fetching available update data. + * + * @param $context + * Reference to an array used for Batch API storage. + */ +function update_fetch_data_batch(&$context) { + $queue = DrupalQueue::get('update_fetch_tasks'); + if (empty($context['sandbox']['max'])) { + $context['finished'] = 0; + $context['sandbox']['max'] = $queue->numberOfItems(); + $context['sandbox']['progress'] = 0; + $context['message'] = t('Checking available update data ...'); + $context['results']['updated'] = 0; + $context['results']['failures'] = 0; + $context['results']['processed'] = 0; + } + + // Grab another item from the fetch queue. + for ($i = 0; $i < 5; $i++) { + if ($item = $queue->claimItem()) { + if (_update_process_fetch_task($item->data)) { + $context['results']['updated']++; + $context['message'] = t('Checked available update data for %title.', array('%title' => $item->data['info']['name'])); + } + else { + $context['message'] = t('Failed to check available update data for %title.', array('%title' => $item->data['info']['name'])); + $context['results']['failures']++; + } + $context['sandbox']['progress']++; + $context['results']['processed']++; + $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; + $queue->deleteItem($item); + } + else { + // If the queue is currently empty, we're done. It's possible that + // another thread might have added new fetch tasks while we were + // processing this batch. In that case, the usual 'finished' math could + // get confused, since we'd end up processing more tasks that we thought + // we had when we started and initialized 'max' with numberOfItems(). By + // forcing 'finished' to be exactly 1 here, we ensure that batch + // processing is terminated. + $context['finished'] = 1; + return; + } + } +} + +/** + * Batch callback: Performs actions when all fetch tasks have been completed. + * + * @param $success + * TRUE if the batch operation was successful; FALSE if there were errors. + * @param $results + * An associative array of results from the batch operation, including the key + * 'updated' which holds the total number of projects we fetched available + * update data for. + */ +function update_fetch_data_finished($success, $results) { + if ($success) { + if (!empty($results)) { + if (!empty($results['updated'])) { + drupal_set_message(format_plural($results['updated'], 'Checked available update data for one project.', 'Checked available update data for @count projects.')); + } + if (!empty($results['failures'])) { + drupal_set_message(format_plural($results['failures'], 'Failed to get available update data for one project.', 'Failed to get available update data for @count projects.'), 'error'); + } + } } else { - drupal_set_message(t('Unable to fetch any information about available new releases and updates.'), 'error'); + drupal_set_message(t('An error occurred trying to get available update data.'), 'error'); } - drupal_goto('admin/reports/updates'); } /** - * Fetch project info via XML from a central server. + * Attempts to drain the queue of tasks for release history data to fetch. */ -function _update_refresh() { - static $fail = array(); +function _update_fetch_data() { + $queue = DrupalQueue::get('update_fetch_tasks'); + $end = time() + variable_get('update_max_fetch_time', UPDATE_MAX_FETCH_TIME); + while (time() < $end && ($item = $queue->claimItem())) { + _update_process_fetch_task($item->data); + $queue->deleteItem($item); + } +} + +/** + * Processes a task to fetch available update data for a single project. + * + * Once the release history XML data is downloaded, it is parsed and saved into + * the {cache_update} table in an entry just for that project. + * + * @param $project + * Associative array of information about the project to fetch data for. + * + * @return + * TRUE if we fetched parsable XML, otherwise FALSE. + */ +function _update_process_fetch_task($project) { global $base_url; + $fail = &drupal_static(__FUNCTION__, array()); + // This can be in the middle of a long-running batch, so REQUEST_TIME won't + // necessarily be valid. + $now = time(); + if (empty($fail)) { + // If we have valid data about release history XML servers that we have + // failed to fetch from on previous attempts, load that from the cache. + if (($cache = _update_cache_get('fetch_failures')) && ($cache->expire > $now)) { + $fail = $cache->data; + } + } + + $max_fetch_attempts = variable_get('update_max_fetch_attempts', UPDATE_MAX_FETCH_ATTEMPTS); + + $success = FALSE; + $available = array(); + $site_key = drupal_hmac_base64($base_url, drupal_get_private_key()); + $url = _update_build_fetch_url($project, $site_key); + $fetch_url_base = _update_get_fetch_url_base($project); + $project_name = $project['name']; + + if (empty($fail[$fetch_url_base]) || $fail[$fetch_url_base] < $max_fetch_attempts) { + $xml = drupal_http_request($url); + if (!isset($xml->error) && isset($xml->data)) { + $data = $xml->data; + } + } + + if (!empty($data)) { + $available = update_parse_xml($data); + // @todo: Purge release data we don't need (http://drupal.org/node/238950). + if (!empty($available)) { + // Only if we fetched and parsed something sane do we return success. + $success = TRUE; + } + } + else { + $available['project_status'] = 'not-fetched'; + if (empty($fail[$fetch_url_base])) { + $fail[$fetch_url_base] = 1; + } + else { + $fail[$fetch_url_base]++; + } + } + + $frequency = variable_get('update_check_frequency', 1); + $cid = 'available_releases::' . $project_name; + _update_cache_set($cid, $available, $now + (60 * 60 * 24 * $frequency)); + + // Stash the $fail data back in the DB for the next 5 minutes. + _update_cache_set('fetch_failures', $fail, $now + (60 * 5)); + + // Whether this worked or not, we did just (try to) check for updates. + variable_set('update_last_check', $now); + + // Now that we processed the fetch task for this project, clear out the + // record in {cache_update} for this task so we're willing to fetch again. + _update_cache_clear('fetch_task::' . $project_name); + + return $success; +} + +/** + * Clears out all the cached available update data and initiates re-fetching. + */ +function _update_refresh() { module_load_include('inc', 'update', 'update.compare'); // Since we're fetching new available update data, we want to clear @@ -35,98 +206,117 @@ function _update_refresh() { _update_cache_clear('update_project_projects'); _update_cache_clear('update_project_data'); - $available = array(); - $data = array(); - $site_key = md5($base_url . drupal_get_private_key()); $projects = update_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_cache_clear('update_available_releases'); - $max_fetch_attempts = variable_get('update_max_fetch_attempts', UPDATE_MAX_FETCH_ATTEMPTS); - + _update_cache_clear('available_releases::', TRUE); + foreach ($projects as $key => $project) { - $url = _update_build_fetch_url($project, $site_key); - $fetch_url_base = _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; - } + update_create_fetch_task($project); } +} - 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'; - } +/** + * Adds a task to the queue for fetching release history data for a project. + * + * We only create a new fetch task if there's no task already in the queue for + * this particular project (based on 'fetch_task::' entries in the + * {cache_update} table). + * + * @param $project + * Associative array of information about a project as created by + * update_get_projects(), including keys such as 'name' (short name), and the + * 'info' array with data from a .info file for the project. + * + * @see update_get_projects() + * @see update_get_available() + * @see update_refresh() + * @see update_fetch_data() + * @see _update_process_fetch_task() + */ +function _update_create_fetch_task($project) { + $fetch_tasks = &drupal_static(__FUNCTION__, array()); + if (empty($fetch_tasks)) { + $fetch_tasks = _update_get_cache_multiple('fetch_task'); + } + $cid = 'fetch_task::' . $project['name']; + if (empty($fetch_tasks[$cid])) { + $queue = DrupalQueue::get('update_fetch_tasks'); + $queue->createItem($project); + // Due to race conditions, it is possible that another process already + // inserted a row into the {cache_update} table and the following query will + // throw an exception. + // @todo: Remove the need for the manual check by relying on a queue that + // enforces unique items. + try { + db_insert('cache_update') + ->fields(array( + 'cid' => $cid, + 'created' => REQUEST_TIME, + )) + ->execute(); } - $frequency = variable_get('update_check_frequency', 1); - _update_cache_set('update_available_releases', $available, time() + (60 * 60 * 24 * $frequency)); - watchdog('update', 'Attempted to fetch information about all available new releases and updates.', array(), WATCHDOG_NOTICE, l(t('view'), 'admin/reports/updates')); - } - else { - watchdog('update', 'Unable to fetch any information about available new releases and updates.', array(), WATCHDOG_ERROR, l(t('view'), 'admin/reports/updates')); + catch (Exception $e) { + // The exception can be ignored safely. + } + $fetch_tasks[$cid] = REQUEST_TIME; } - // Whether this worked or not, we did just (try to) check for updates. - variable_set('update_last_check', time()); - 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 + * 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). + * (optional) The anonymous site key hash. Defaults to an empty string. * - * @see update_refresh() + * @return + * The URL for fetching information about updates to the specified project. + * + * @see update_fetch_data() + * @see _update_process_fetch_task() * @see update_get_projects() */ function _update_build_fetch_url($project, $site_key = '') { $name = $project['name']; $url = _update_get_fetch_url_base($project); - $url .= '/'. $name .'/'. DRUPAL_CORE_COMPATIBILITY; - // Only append a site_key and the version information if we have a site_key - // in the first place, and if this is not a disabled module or theme. We do - // not want to record usage statistics for disabled code. + $url .= '/' . $name . '/' . DRUPAL_CORE_COMPATIBILITY; + + // Only append usage information if we have a site key and the project is + // enabled. We do not want to record usage statistics for disabled projects. if (!empty($site_key) && (strpos($project['project_type'], 'disabled') === FALSE)) { - $url .= (strpos($url, '?') === TRUE) ? '&' : '?'; + // Append the site key. + $url .= (strpos($url, '?') !== FALSE) ? '&' : '?'; $url .= 'site_key='; $url .= rawurlencode($site_key); + + // Append the version. if (!empty($project['info']['version'])) { $url .= '&version='; $url .= rawurlencode($project['info']['version']); } + + // Append the list of modules or themes enabled. + $list = array_keys($project['includes']); + $url .= '&list='; + $url .= rawurlencode(implode(',', $list)); } return $url; } /** - * Return the base of the URL to fetch available update data for a project. + * Returns the base of the URL to fetch available update data for a project. * * @param $project * The array of project information from update_get_projects(). + * * @return * The base of the URL used for fetching available update data. This does * not include the path elements to specify a particular project, version, @@ -139,21 +329,21 @@ function _update_get_fetch_url_base($pro } /** - * Perform any notifications that should be done once cron fetches new data. + * Performs 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, notifies administrators via email if there + * This method checks the status of the site using the new data and, depending + * on the configuration of the site, notifies administrators via e-mail if there * are new releases or missing security updates. * * @see update_requirements() */ function _update_cron_notify() { - include_once './includes/install.inc'; + module_load_install('update'); $status = update_requirements('runtime'); $params = array(); $notify_all = (variable_get('update_notification_threshold', 'all') == 'all'); foreach (array('core', 'contrib') as $report_type) { - $type = 'update_'. $report_type; + $type = 'update_' . $report_type; if (isset($status[$type]['severity']) && ($status[$type]['severity'] == REQUIREMENT_ERROR || ($notify_all && $status[$type]['reason'] == UPDATE_NOT_CURRENT))) { $params[$report_type] = $status[$type]['reason']; @@ -164,121 +354,70 @@ function _update_cron_notify() { if (!empty($notify_list)) { $default_language = language_default(); foreach ($notify_list as $target) { - if ($target_user = user_load(array('mail' => $target))) { + if ($target_user = user_load_by_mail($target)) { $target_language = user_preferred_language($target_user); } else { $target_language = $default_language; } - drupal_mail('update', 'status_notify', $target, $target_language, $params); + $message = drupal_mail('update', 'status_notify', $target, $target_language, $params); + // Track when the last mail was successfully sent to avoid sending + // too many e-mails. + if ($message['result']) { + variable_set('update_last_email_notification', REQUEST_TIME); + } } } } } /** - * XML Parser object to read Drupal's release history info files. - * This uses PHP4's lame XML parsing, but it works. + * Parses the XML of the Drupal release history info files. + * + * @param $raw_xml + * A raw XML string of available release data for a given project. + * + * @return + * Array of parsed data about releases for a given project, or NULL if there + * was an error parsing the string. */ -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; - case 'FILE': - unset($this->current_object); - $this->current_file = array(); - $this->current_object = &$this->current_file; - 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; - case 'FILE': - unset($this->current_object); - $this->current_release['files'][] = $this->current_file; - break; - case 'FILES': - $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 update_parse_xml($raw_xml) { + try { + $xml = new SimpleXMLElement($raw_xml); + } + catch (Exception $e) { + // SimpleXMLElement::__construct produces an E_WARNING error message for + // each error found in the XML data and throws an exception if errors + // were detected. Catch any exception and return failure (NULL). + return; + } + // If there is no valid project data, the XML is invalid, so return failure. + if (!isset($xml->short_name)) { + return; } - - function data($parser, $data) { - if ($this->current_tag && !in_array($this->current_tag, array('PROJECT', 'RELEASE', 'RELEASES', 'TERM', 'TERMS', 'FILE', 'FILES'))) { - $tag = strtolower($this->current_tag); - if (isset($this->current_object[$tag])) { - $this->current_object[$tag] .= $data; + $short_name = (string) $xml->short_name; + $data = array(); + foreach ($xml as $k => $v) { + $data[$k] = (string) $v; + } + $data['releases'] = array(); + if (isset($xml->releases)) { + foreach ($xml->releases->children() as $release) { + $version = (string) $release->version; + $data['releases'][$version] = array(); + foreach ($release->children() as $k => $v) { + $data['releases'][$version][$k] = (string) $v; } - else { - $this->current_object[$tag] = $data; + $data['releases'][$version]['terms'] = array(); + if ($release->terms) { + foreach ($release->terms->children() as $term) { + if (!isset($data['releases'][$version]['terms'][(string) $term->name])) { + $data['releases'][$version]['terms'][(string) $term->name] = array(); + } + $data['releases'][$version]['terms'][(string) $term->name][] = (string) $term->value; + } } } } + return $data; } diff -rup /Users/webchick/Sites/6.x/modules/update/update.info /Users/webchick/Sites/7.x/modules/update/update.info --- /Users/webchick/Sites/6.x/modules/update/update.info 2014-01-11 21:40:30.000000000 -0800 +++ /Users/webchick/Sites/7.x/modules/update/update.info 2012-12-31 14:20:25.000000000 -0800 @@ -1,5 +1,7 @@ -name = Update status -description = Checks the status of available updates for Drupal and your installed modules and themes. +name = Update manager +description = Checks for available updates, and can securely install or update modules and themes via a web interface. version = VERSION -package = Core - optional -core = 6.x +package = Core +core = 7.x +files[] = update.test +configure = admin/reports/updates/settings diff -rup /Users/webchick/Sites/6.x/modules/update/update.install /Users/webchick/Sites/7.x/modules/update/update.install --- /Users/webchick/Sites/6.x/modules/update/update.install 2013-02-19 13:25:56.000000000 -0800 +++ /Users/webchick/Sites/7.x/modules/update/update.install 2012-12-31 14:20:25.000000000 -0800 @@ -1,62 +1,190 @@ createQueue(); } /** - * Implementation of hook_uninstall(). + * Implements 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_last_email_notification', 'update_notification_threshold', 'update_notify_emails', + 'update_max_fetch_attempts', + 'update_max_fetch_time', ); foreach ($variables as $variable) { variable_del($variable); } + $queue = DrupalQueue::get('update_fetch_tasks'); + $queue->deleteQueue(); +} + +/** + * Fills in the requirements array. + * + * This is shared for both core and contrib to generate the right elements in + * the array for hook_requirements(). + * + * @param $project + * Array of information about the project we're testing as returned by + * update_calculate_project_data(). + * @param $type + * What kind of project this is ('core' or 'contrib'). + * + * @return + * An array to be included in the nested $requirements array. + * + * @see hook_requirements() + * @see update_requirements() + * @see update_calculate_project_data() + */ +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, update_manager_access() ? 'admin/reports/updates/update' : 'admin/reports/updates'); + return $requirement; } /** - * Implementation of hook_schema(). + * @addtogroup updates-6.x-to-7.x + * @{ */ -function update_schema() { - $schema['cache_update'] = drupal_get_schema_unprocessed('system', 'cache'); - $schema['cache_update']['description'] = 'Cache table for the Update module to store information about available releases, fetched from central server.'; - return $schema; + +/** + * Create a queue to store tasks for requests to fetch available update data. + */ +function update_update_7000() { + module_load_include('inc', 'system', 'system.queue'); + $queue = DrupalQueue::get('update_fetch_tasks'); + $queue->createQueue(); } /** - * Private helper to clear out stale variables from update_status 5.x contrib. + * Recreates cache_update table. * - * @see update_install() - * @see update_update_6000() + * Converts fields that hold serialized variables from text to blob. + * Removes 'headers' column. */ -function _update_remove_update_status_variables() { - variable_del('update_status_settings'); - variable_del('update_status_notify_emails'); - variable_del('update_status_check_frequency'); - variable_del('update_status_notification_threshold'); - variable_del('update_status_last'); - variable_del('update_status_fetch_url'); +function update_update_7001() { + $schema = system_schema_cache_7054(); + + db_drop_table('cache_update'); + db_create_table('cache_update', $schema); } /** - * Clear out stale variables from update_status. + * @} End of "addtogroup updates-6.x-to-7.x". */ -function update_update_6000() { - _update_remove_update_status_variables(); - return array(); -} Only in /Users/webchick/Sites/7.x/modules/update: update.manager.inc diff -rup /Users/webchick/Sites/6.x/modules/update/update.module /Users/webchick/Sites/7.x/modules/update/update.module --- /Users/webchick/Sites/6.x/modules/update/update.module 2014-01-11 21:40:30.000000000 -0800 +++ /Users/webchick/Sites/7.x/modules/update/update.module 2014-01-07 16:26:20.000000000 -0800 @@ -2,10 +2,13 @@ /** * @file - * 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. + * Handles updates of Drupal core and contributed projects. + * + * The 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 e-mail. It also provides the + * ability to install contributed modules and themes via an user interface. */ /** @@ -56,70 +59,108 @@ define('UPDATE_UNKNOWN', -2); define('UPDATE_NOT_FETCHED', -3); /** + * We need to (re)fetch available update data for this project. + */ +define('UPDATE_FETCH_PENDING', -4); + +/** * Maximum number of attempts to fetch available update data from a given host. */ define('UPDATE_MAX_FETCH_ATTEMPTS', 2); /** - * Implementation of hook_help(). + * Maximum number of seconds to try fetching available update data at a time. + */ +define('UPDATE_MAX_FETCH_TIME', 5); + +/** + * Implements hook_help(). */ function update_help($path, $arg) { switch ($path) { case 'admin/reports/updates': - $output = '

'. 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.') .'

'; - $output .= '

'. t('To extend the functionality or to change the look of your site, a number of contributed modules and themes are available.', array('@modules' => 'http://drupal.org/project/modules', '@themes' => 'http://drupal.org/project/themes')) .'

'; + return '

' . 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.') . '

'; + + case 'admin/help#update': + $output = ''; + $output .= '

' . t('About') . '

'; + $output .= '

' . t("The Update manager module periodically checks for new versions of your site's software (including contributed modules and themes), and alerts administrators to available updates. In order to provide update information, anonymous usage statistics are sent to Drupal.org. If desired, you may disable the Update manager module from the Module administration page. For more information, see the online handbook entry for Update manager module.", array('@update' => 'http://drupal.org/documentation/modules/update', '@modules' => url('admin/modules'))) . '

'; + // Only explain the Update manager if it has not been disabled. + if (update_manager_access()) { + $output .= '

' . t('The Update manager also allows administrators to update and install modules and themes through the administration interface.') . '

'; + } + $output .= '

' . t('Uses') . '

'; + $output .= '
'; + $output .= '
' . t('Checking for available updates') . '
'; + $output .= '
' . t('A report of available updates will alert you when new releases are available for download. You may configure options for the frequency for checking updates (which are performed during cron runs) and e-mail notifications at the Update manager settings page.', array('@update-report' => url('admin/reports/updates'), '@cron' => 'http://drupal.org/cron', '@update-settings' => url('admin/reports/updates/settings'))) . '
'; + // Only explain the Update manager if it has not been disabled. + if (update_manager_access()) { + $output .= '
' . t('Performing updates through the user interface') . '
'; + $output .= '
' . t('The Update manager module allows administrators to perform updates directly through the administration interface. At the top of the modules and themes pages you will see a link to update to new releases. This will direct you to the update page where you see a listing of all the missing updates and confirm which ones you want to upgrade. From there, you are prompted for your FTP/SSH password, which then transfers the files into your Drupal installation, overwriting your old files. More detailed instructions can be found in the online handbook.', array('@modules_page' => url('admin/modules'), '@themes_page' => url('admin/appearance'), '@update-page' => url('admin/reports/updates/update'), '@update' => 'http://drupal.org/documentation/modules/update')) . '
'; + $output .= '
' . t('Installing new modules and themes through the user interface') . '
'; + $output .= '
' . t('You can also install new modules and themes in the same fashion, through the install page, or by clicking the Install new module/theme link at the top of the modules and themes pages. In this case, you are prompted to provide either the URL to the download, or to upload a packaged release file from your local computer.', array('@modules_page' => url('admin/modules'), '@themes_page' => url('admin/appearance'), '@install' => url('admin/reports/updates/install'))) . '
'; + } + $output .= '
'; 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; + } +} + +/** + * Implements hook_init(). + */ +function update_init() { + if (arg(0) == 'admin' && user_access('administer site configuration')) { + switch ($_GET['q']) { + // These pages don't need additional nagging. + case 'admin/appearance/update': + case 'admin/appearance/install': + case 'admin/modules/update': + case 'admin/modules/install': + case 'admin/reports/updates': + case 'admin/reports/updates/update': + case 'admin/reports/updates/install': + case 'admin/reports/updates/settings': + case 'admin/reports/status': + case 'admin/update/ready': + return; + + // If we are on the appearance or modules list, display a detailed report + // of the update status. + case 'admin/appearance': + case 'admin/modules': + $verbose = TRUE; + break; + + } + module_load_install('update'); + $status = update_requirements('runtime'); + foreach (array('core', 'contrib') as $report_type) { + $type = 'update_' . $report_type; + if (!empty($verbose)) { if (isset($status[$type]['severity'])) { if ($status[$type]['severity'] == REQUIREMENT_ERROR) { - drupal_set_message($status[$type]['description'], 'error'); + drupal_set_message($status[$type]['description'], 'error', FALSE); } elseif ($status[$type]['severity'] == REQUIREMENT_WARNING) { - drupal_set_message($status[$type]['description'], 'warning'); + drupal_set_message($status[$type]['description'], 'warning', FALSE); } } } - return '

'. t('See the available updates page for information on installed modules and themes with new versions released.', array('@available_updates' => url('admin/reports/updates'))) .'

'; - - case 'admin/reports/updates/settings': - case 'admin/reports/status': - // These two pages don't need additional nagging. - break; - - case 'admin/help#update': - $output = '

'. 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.") .'

'; - $output .= '

'. t('The report of available updates will alert you when new releases are available for download. You may configure options for update checking frequency and notifications at the Update status module settings page.', array('@update-report' => url('admin/reports/updates'), '@update-settings' => url('admin/reports/updates/settings'))) .'

'; - $output .= '

'. 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 module administration page.', array('@modules' => url('admin/build/modules'))) .'

'; - $output .= '

'. t('For more information, see the online handbook entry for Update status module.', array('@update' => 'http://drupal.org/handbook/modules/update')) .'

'; - return $output; - - default: // Otherwise, if we're on *any* admin page and there's a security // update missing, print an error message about it. - 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'); - } + else { + if (isset($status[$type]) + && isset($status[$type]['reason']) + && $status[$type]['reason'] === UPDATE_NOT_SECURE) { + drupal_set_message($status[$type]['description'], 'error', FALSE); } } - + } } } /** - * Implementation of hook_menu(). + * Implements hook_menu(). */ function update_menu() { $items = array(); @@ -129,14 +170,12 @@ function update_menu() { 'description' => 'Get a status report about available updates for your installed modules and themes.', 'page callback' => 'update_status', 'access arguments' => array('administer site configuration'), + 'weight' => -50, '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( @@ -146,236 +185,281 @@ function update_menu() { 'access arguments' => array('administer site configuration'), 'file' => 'update.settings.inc', 'type' => MENU_LOCAL_TASK, + 'weight' => 50, ); $items['admin/reports/updates/check'] = array( 'title' => 'Manual update check', 'page callback' => 'update_manual_status', 'access arguments' => array('administer site configuration'), + 'type' => MENU_CALLBACK, 'file' => 'update.fetch.inc', + ); + + // We want action links for updating projects at a few different locations: + // both the module and theme administration pages, and on the available + // updates report itself. The menu items will be mostly identical, except the + // paths and titles, so we just define them in a loop. We pass in a string + // indicating what context we're entering the action from, so that can + // customize the appearance as needed. + $paths = array( + 'report' => 'admin/reports/updates', + 'module' => 'admin/modules', + 'theme' => 'admin/appearance', + ); + foreach ($paths as $context => $path) { + $items[$path . '/install'] = array( + 'page callback' => 'drupal_get_form', + 'page arguments' => array('update_manager_install_form', $context), + 'access callback' => 'update_manager_access', + 'access arguments' => array(), + 'weight' => 25, + 'type' => MENU_LOCAL_ACTION, + 'file' => 'update.manager.inc', + ); + $items[$path . '/update'] = array( + 'page callback' => 'drupal_get_form', + 'page arguments' => array('update_manager_update_form', $context), + 'access callback' => 'update_manager_access', + 'access arguments' => array(), + 'weight' => 10, + 'title' => 'Update', + 'type' => MENU_LOCAL_TASK, + 'file' => 'update.manager.inc', + ); + } + // Customize the titles of the action links depending on where they appear. + // We use += array() to let the translation extractor find these menu titles. + $items['admin/reports/updates/install'] += array('title' => 'Install new module or theme'); + $items['admin/modules/install'] += array('title' => 'Install new module'); + $items['admin/appearance/install'] += array('title' => 'Install new theme'); + + // Menu callback used for the confirmation page after all the releases + // have been downloaded, asking you to backup before installing updates. + $items['admin/update/ready'] = array( + 'title' => 'Ready to update', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('update_manager_update_ready_form'), + 'access callback' => 'update_manager_access', + 'access arguments' => array(), 'type' => MENU_CALLBACK, + 'file' => 'update.manager.inc', ); return $items; } /** - * Implementation of the hook_theme() registry. + * Access callback: Resolves if the current user can access updater menu items. + * + * It both enforces the 'administer software updates' permission and the global + * kill switch for the authorize.php script. + * + * @return + * TRUE if the current user can access the updater menu items; FALSE + * otherwise. + * + * @see update_menu() + */ +function update_manager_access() { + return variable_get('allow_authorize_operations', TRUE) && user_access('administer software updates'); +} + +/** + * Implements hook_theme(). */ function update_theme() { return array( - 'update_settings' => array( - 'arguments' => array('form' => NULL), + 'update_manager_update_form' => array( + 'render element' => 'form', + 'file' => 'update.manager.inc', + ), + 'update_last_check' => array( + 'variables' => array('last' => NULL), ), 'update_report' => array( - 'arguments' => array('data' => NULL), + 'variables' => array('data' => NULL), ), 'update_version' => array( - 'arguments' => array('version' => NULL, 'tag' => NULL, 'class' => NULL), + 'variables' => array('version' => NULL, 'tag' => NULL, 'class' => array()), + ), + 'update_status_label' => array( + 'variables' => array('status' => NULL), ), ); } /** - * Implementation of hook_requirements(). - * - * @return - * An array describing the status of the site regarding available updates. - * If there is no update data, only one record will be returned, indicating - * that the status of core can't be determined. If data is available, there - * will be two records: one for core, and another for all of contrib - * (assuming there are any contributed modules or themes enabled on the - * site). In addition to the fields expected by hook_requirements ('value', - * 'severity', and optionally 'description'), this array will contain a - * 'reason' attribute, which is an integer constant to indicate why the - * given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or - * UPDATE_UNKNOWN). This is used for generating the appropriate e-mail - * notification messages during update_cron(), and might be useful for other - * modules that invoke update_requirements() to find out if the site is up - * to date or not. - * - * @see _update_message_text() - * @see _update_cron_notify() + * Implements hook_cron(). */ -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); - // First, populate the requirements for core: - $requirements['update_core'] = _update_requirement_check($data['drupal'], 'core'); - // We don't want to check drupal a second time. - unset($data['drupal']); - if (!empty($data)) { - // Now, sort our $data array based on each project's status. The - // status constants are numbered in the right order of precedence, so - // we just need to make sure the projects are sorted in ascending - // order of status, and we can look at the first project we find. - 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_cron() { + $frequency = variable_get('update_check_frequency', 1); + $interval = 60 * 60 * 24 * $frequency; + if ((REQUEST_TIME - variable_get('update_last_check', 0)) > $interval) { + // If the configured update interval has elapsed, we want to invalidate + // the cached data for all projects, attempt to re-fetch, and trigger any + // configured notifications about the new status. + update_refresh(); + update_fetch_data(); } + else { + // Otherwise, see if any individual projects are now stale or still + // missing data, and if so, try to fetch the data. + update_get_available(TRUE); + } + if ((REQUEST_TIME - variable_get('update_last_email_notification', 0)) > $interval) { + // If configured time between notifications elapsed, send email about + // updates possibly available. + module_load_include('inc', 'update', 'update.fetch'); + _update_cron_notify(); + } + + // Clear garbage from disk. + update_clear_update_disk_cache(); } /** - * Private helper method to fill in the requirements array. - * - * This is shared for both core and contrib to generate the right elements in - * the array for hook_requirements(). + * Implements hook_themes_enabled(). * - * @param $project - * Array of information about the project we're testing as returned by - * update_calculate_project_data(). - * @param $type - * What kind of project is this ('core' or 'contrib'). - * - * @return - * An array to be included in the nested $requirements array. - * - * @see hook_requirements() - * @see update_requirements() - * @see update_calculate_project_data() - */ -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; + * If themes are enabled, we invalidate the cache of available updates. + */ +function update_themes_enabled($themes) { + // Clear all update module caches. + _update_cache_clear(); } /** - * Implementation of hook_cron(). + * Implements hook_themes_disabled(). + * + * If themes are disabled, we invalidate the cache of available updates. */ -function update_cron() { - $frequency = variable_get('update_check_frequency', 1); - $interval = 60 * 60 * 24 * $frequency; - // Cron should check for updates if there is no update data cached or if the - // configured update interval has elapsed. - if (!_update_cache_get('update_available_releases') || ((time() - variable_get('update_last_check', 0)) > $interval)) { - update_refresh(); - _update_cron_notify(); - } +function update_themes_disabled($themes) { + // Clear all update module caches. + _update_cache_clear(); } /** - * Implementation of hook_form_alter(). + * Implements hook_form_FORM_ID_alter() for system_modules(). * - * Adds a submit handler to the system modules and themes forms, so that if a - * site admin saves either form, we invalidate the cache of available updates. + * Adds a form submission handler to the system modules form, so that if a site + * admin saves the form, we invalidate the cache of available updates. * - * @see update_invalidate_cache() + * @see _update_cache_clear() */ -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_form_system_modules_alter(&$form, $form_state) { + $form['#submit'][] = 'update_cache_clear_submit'; } /** - * Prints a warning message when there is no data about available updates. + * Form submission handler for system_modules(). + * + * @see update_form_system_modules_alter() + */ +function update_cache_clear_submit($form, &$form_state) { + // Clear all update module caches. + _update_cache_clear(); +} + +/** + * Returns a warning message when there is no data about available updates. */ 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 run cron or you can check manually. Please note that checking for available updates can take a long time, so please be patient.', array( + return t('No update information available. Run cron or check manually.', array( '@run_cron' => url('admin/reports/status/run-cron', array('query' => $destination)), '@check_manually' => url('admin/reports/updates/check', array('query' => $destination)), )); } /** - * Internal helper to try to get the update information from the cache - * if possible, and to refresh the cache when necessary. + * Tries to get update information from cache and refreshes it when necessary. * * In addition to checking the cache lifetime, this function also ensures that * there are no .info files for enabled modules or themes that have a newer * modification timestamp than the last time we checked for available update - * data. If any .info file was modified, it almost certainly means a new - * version of something was installed. Without fresh available update data, - * the logic in update_calculate_project_data() will be wrong and produce - * confusing, bogus results. + * data. If any .info file was modified, it almost certainly means a new version + * of something was installed. Without fresh available update data, the logic in + * update_calculate_project_data() will be wrong and produce confusing, bogus + * results. * * @param $refresh - * Boolean to indicate if this method should refresh the cache automatically - * if there's no data. + * (optional) Boolean to indicate if this method should refresh the cache + * automatically if there's no data. Defaults to FALSE. + * + * @return + * Array of data about available releases, keyed by project shortname. * * @see update_refresh() * @see update_get_projects() */ function update_get_available($refresh = FALSE) { module_load_include('inc', 'update', 'update.compare'); - $available = array(); - - // First, make sure that none of the .info files have a change time - // newer than the last time we checked for available updates. $needs_refresh = FALSE; - $last_check = variable_get('update_last_check', 0); + + // Grab whatever data we currently have cached in the DB. + $available = _update_get_cached_available_releases(); + $num_avail = count($available); + $projects = update_get_projects(); foreach ($projects as $key => $project) { - if ($project['info']['_info_file_ctime'] > $last_check) { + // If there's no data at all, we clearly need to fetch some. + if (empty($available[$key])) { + update_create_fetch_task($project); + $needs_refresh = TRUE; + continue; + } + + // See if the .info file is newer than the last time we checked for data, + // and if so, mark this project's data as needing to be re-fetched. Any + // time an admin upgrades their local installation, the .info file will + // be changed, so this is the only way we can be sure we're not showing + // bogus information right after they upgrade. + if ($project['info']['_info_file_ctime'] > $available[$key]['last_fetch']) { + $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING; + } + + // If we have project data but no release data, we need to fetch. This + // can be triggered when we fail to contact a release history server. + if (empty($available[$key]['releases'])) { + $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING; + } + + // If we think this project needs to fetch, actually create the task now + // and remember that we think we're missing some data. + if (!empty($available[$key]['fetch_status']) && $available[$key]['fetch_status'] == UPDATE_FETCH_PENDING) { + update_create_fetch_task($project); $needs_refresh = TRUE; - break; } } - if (!$needs_refresh && ($cache = _update_cache_get('update_available_releases')) && $cache->expire > time()) { - $available = $cache->data; - } - elseif ($needs_refresh || $refresh) { - // If we need to refresh due to a newer .info file, ignore the argument - // and force the refresh (e.g., even for update_requirements()) to prevent - // bogus results. - $available = update_refresh(); + + if ($needs_refresh && $refresh) { + // Attempt to drain the queue of fetch tasks. + update_fetch_data(); + // After processing the queue, we've (hopefully) got better data, so pull + // the latest from the cache again and use that directly. + $available = _update_get_cached_available_releases(); } + return $available; } /** - * Wrapper to load the include file and then refresh the release data. + * Creates a new fetch task after loading the necessary include file. + * + * @param $project + * Associative array of information about a project. See update_get_projects() + * for the keys used. + * + * @see _update_create_fetch_task() + */ +function update_create_fetch_task($project) { + module_load_include('inc', 'update', 'update.fetch'); + return _update_create_fetch_task($project); +} + +/** + * Refreshes the release data after loading the necessary include file. + * + * @see _update_refresh() */ function update_refresh() { module_load_include('inc', 'update', 'update.fetch'); @@ -383,19 +467,52 @@ function update_refresh() { } /** - * Implementation of hook_mail(). + * Attempts to fetch update data after loading the necessary include file. * - * Constructs the email notification message when the site is out of date. + * @see _update_fetch_data() + */ +function update_fetch_data() { + module_load_include('inc', 'update', 'update.fetch'); + return _update_fetch_data(); +} + +/** + * Returns all currently cached data about available releases for all projects. + * + * @return + * Array of data about available releases, keyed by project shortname. + */ +function _update_get_cached_available_releases() { + $data = array(); + $cache_items = _update_get_cache_multiple('available_releases'); + foreach ($cache_items as $cid => $cache) { + $cache->data['last_fetch'] = $cache->created; + if ($cache->expire < REQUEST_TIME) { + $cache->data['fetch_status'] = UPDATE_FETCH_PENDING; + } + // The project shortname is embedded in the cache ID, even if there's no + // data for this project in the DB at all, so use that for the indexes in + // the array. + $parts = explode('::', $cid, 2); + $data[$parts[1]] = $cache->data; + } + return $data; +} + +/** + * Implements hook_mail(). + * + * Constructs the e-mail notification message when the site is out of date. * * @param $key * Unique key to indicate what message to build, always 'status_notify'. * @param $message * Reference to the message array being built. * @param $params - * Array of parameters to indicate what kind of text to include in the - * message body. This is a keyed array of message type ('core' or 'contrib') - * as the keys, and the status reason constant (UPDATE_NOT_SECURE, etc) for - * the values. + * Array of parameters to indicate what kind of text to include in the message + * body. This is a keyed array of message type ('core' or 'contrib') as the + * keys, and the status reason constant (UPDATE_NOT_SECURE, etc) for the + * values. * * @see drupal_mail() * @see _update_cron_notify() @@ -404,30 +521,41 @@ function 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); + $message['subject'] .= t('New release(s) available for !site_name', array('!site_name' => variable_get('site_name', 'Drupal')), array('langcode' => $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)); + $message['body'][] = t('See the available updates page for more information:', array(), array('langcode' => $langcode)) . "\n" . url('admin/reports/updates', array('absolute' => TRUE, 'language' => $language)); + if (update_manager_access()) { + $message['body'][] = t('You can automatically install your missing updates using the Update manager:', array(), array('langcode' => $langcode)) . "\n" . url('admin/reports/updates/update', array('absolute' => TRUE, 'language' => $language)); + } + $settings_url = url('admin/reports/updates/settings', array('absolute' => TRUE)); + if (variable_get('update_notification_threshold', 'all') == 'all') { + $message['body'][] = t('Your site is currently configured to send these emails when any updates are available. To get notified only for security updates, !url.', array('!url' => $settings_url)); + } + else { + $message['body'][] = t('Your site is currently configured to send these emails only when security updates are available. To get notified for any available updates, !url.', array('!url' => $settings_url)); + } } /** - * Helper function to return the appropriate message text when the site is out - * of date or missing a security update. + * Returns the appropriate message text when site is out of date or not secure. * * These error messages are shared by both update_requirements() for the * site-wide status report at admin/reports/status and in the body of the - * notification emails generated by update_cron(). + * notification e-mail messages generated by update_cron(). * * @param $msg_type - * String to indicate what kind of message to generate. Can be either - * 'core' or 'contrib'. + * String to indicate what kind of message to generate. Can be either 'core' + * or 'contrib'. * @param $msg_reason * Integer constant specifying why message is generated. * @param $report_link - * Boolean that controls if a link to the updates report should be added. + * (optional) Boolean that controls if a link to the updates report should be + * added. Defaults to FALSE. * @param $language - * An optional language object to use. + * (optional) A language object to use. Defaults to NULL. + * * @return * The properly translated error message for the given key. */ @@ -437,64 +565,69 @@ function _update_message_text($msg_type, 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); + $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(), array('langcode' => $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); + $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(), array('langcode' => $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); + $text = t('Your version of Drupal has been revoked and is no longer available for download. Upgrading is strongly recommended!', array(), array('langcode' => $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); + $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(), array('langcode' => $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); + $text = t('Your version of Drupal is no longer supported. Upgrading is strongly recommended!', array(), array('langcode' => $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); + $text = t('The installed version of at least one of your modules or themes is no longer supported. Upgrading or disabling is strongly recommended. See the project homepage for more details.', array(), array('langcode' => $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); + $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(), array('langcode' => $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); + $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(), array('langcode' => $langcode)); } break; case UPDATE_UNKNOWN: case UPDATE_NOT_CHECKED: case UPDATE_NOT_FETCHED: + case UPDATE_FETCH_PENDING: if ($msg_type == 'core') { - $text = t('There was a problem determining the status of available updates for your version of Drupal.', array(), $langcode); + $text = t('There was a problem checking available updates for Drupal.', array('@update-report' => url('admin/reports/updates')), array('langcode' => $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); + $text = t('There was a problem checking available updates for your modules or themes.', array('@update-report' => url('admin/reports/updates')), array('langcode' => $langcode)); } break; } if ($report_link) { - $text .= ' '. t('See the available updates page for more information.', array('@available_updates' => url('admin/reports/updates', array('language' => $language))), $langcode); + if (update_manager_access()) { + $text .= ' ' . t('See the available updates page for more information and to install your missing updates.', array('@available_updates' => url('admin/reports/updates/update', array('language' => $language))), array('langcode' => $langcode)); + } + else { + $text .= ' ' . t('See the available updates page for more information.', array('@available_updates' => url('admin/reports/updates', array('language' => $language))), array('langcode' => $langcode)); + } } return $text; } /** - * Private sort function to order projects based on their status. + * Orders projects based on their status. * - * @see update_requirements() - * @see uasort() + * Callback for uasort() within update_requirements(). */ function _update_project_status_sort($a, $b) { // The status constants are numerically in the right order, so we can @@ -507,30 +640,118 @@ function _update_project_status_sort($a, } /** + * Returns HTML for the last time we checked for update data. + * + * In addition to properly formatting the given timestamp, this function also + * provides a "Check manually" link that refreshes the available update and + * redirects back to the same page. + * + * @param $variables + * An associative array containing: + * - last: The timestamp when the site last checked for available updates. + * + * @see theme_update_report() + * @see theme_update_available_updates_form() + * @ingroup themeable + */ +function theme_update_last_check($variables) { + $last = $variables['last']; + $output = '
'; + $output .= $last ? t('Last checked: @time ago', array('@time' => format_interval(REQUEST_TIME - $last))) : t('Last checked: never'); + $output .= ' (' . l(t('Check manually'), 'admin/reports/updates/check', array('query' => drupal_get_destination())) . ')'; + $output .= "
\n"; + return $output; +} + +/** + * Implements hook_verify_update_archive(). + * + * First, we ensure that the archive isn't a copy of Drupal core, which the + * update manager does not yet support. See http://drupal.org/node/606592 + * + * Then, we make sure that at least one module included in the archive file has + * an .info file which claims that the code is compatible with the current + * version of Drupal core. + * + * @see drupal_system_listing() + * @see _system_rebuild_module_data() + */ +function update_verify_update_archive($project, $archive_file, $directory) { + $errors = array(); + + // Make sure this isn't a tarball of Drupal core. + if ( + file_exists("$directory/$project/index.php") + && file_exists("$directory/$project/update.php") + && file_exists("$directory/$project/includes/bootstrap.inc") + && file_exists("$directory/$project/modules/node/node.module") + && file_exists("$directory/$project/modules/system/system.module") + ) { + return array( + 'no-core' => t('Automatic updating of Drupal core is not supported. See the upgrade guide for information on how to update Drupal core manually.', array('@upgrade-guide' => 'http://drupal.org/upgrade')), + ); + } + + // Parse all the .info files and make sure at least one is compatible with + // this version of Drupal core. If one is compatible, then the project as a + // whole is considered compatible (since, for example, the project may ship + // with some out-of-date modules that are not necessary for its overall + // functionality). + $compatible_project = FALSE; + $incompatible = array(); + $files = file_scan_directory("$directory/$project", '/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info$/', array('key' => 'name', 'min_depth' => 0)); + foreach ($files as $key => $file) { + // Get the .info file for the module or theme this file belongs to. + $info = drupal_parse_info_file($file->uri); + + // If the module or theme is incompatible with Drupal core, set an error. + if (empty($info['core']) || $info['core'] != DRUPAL_CORE_COMPATIBILITY) { + $incompatible[] = !empty($info['name']) ? $info['name'] : t('Unknown'); + } + else { + $compatible_project = TRUE; + break; + } + } + + if (empty($files)) { + $errors[] = t('%archive_file does not contain any .info files.', array('%archive_file' => drupal_basename($archive_file))); + } + elseif (!$compatible_project) { + $errors[] = format_plural( + count($incompatible), + '%archive_file contains a version of %names that is not compatible with Drupal !version.', + '%archive_file contains versions of modules or themes that are not compatible with Drupal !version: %names', + array('!version' => DRUPAL_CORE_COMPATIBILITY, '%archive_file' => drupal_basename($archive_file), '%names' => implode(', ', $incompatible)) + ); + } + + return $errors; +} + +/** * @defgroup update_status_cache Private update status cache system * @{ + * Functions to manage the update status cache. * * We specifically do NOT use the core cache API for saving the fetched data * about available updates. It is vitally important that this cache is only * cleared when we're populating it after successfully fetching new available * update data. Usage of the core cache API results in all sorts of potential * problems that would result in attempting to fetch available update data all - * the time, including if a site has a "minimum cache lifetime" (which is both - * a minimum and a maximum) defined, or if a site uses memcache or another - * plug-able cache system that assumes volatile caches. - * - * Update module still uses the {cache_update} table, but instead of using - * cache_set(), cache_get(), and cache_clear_all(), there are private helper - * functions that implement these same basic tasks but ensure that the cache - * is not prematurely cleared, and that the data is always stored in the + * the time, including if a site has a "minimum cache lifetime" (which is both a + * minimum and a maximum) defined, or if a site uses memcache or another + * pluggable cache system that assumes volatile caches. + * + * The Update Manager module still uses the {cache_update} table, but instead of + * using cache_set(), cache_get(), and cache_clear_all(), there are private + * helper functions that implement these same basic tasks but ensure that the + * cache is not prematurely cleared, and that the data is always stored in the * database, even if memcache or another cache backend is in use. */ /** - * Store data in the private update status cache table. - * - * Note: this function completely ignores the {cache_update}.headers field - * since that is meaningless for the kinds of data we're caching. + * Stores data in the private update status cache table. * * @param $cid * The cache ID to save the data with. @@ -539,35 +760,45 @@ function _update_project_status_sort($a, * @param $expire * One of the following values: * - CACHE_PERMANENT: Indicates that the item should never be removed except - * by explicitly using _update_cache_clear() or update_invalidate_cache(). + * by explicitly using _update_cache_clear(). * - A Unix timestamp: Indicates that the item should be kept at least until * the given time, after which it will be invalidated. + * + * @see _update_cache_get() */ function _update_cache_set($cid, $data, $expire) { - $serialized = 0; - if (is_object($data) || is_array($data)) { - $data = serialize($data); - $serialized = 1; + $fields = array( + 'created' => REQUEST_TIME, + 'expire' => $expire, + ); + if (!is_string($data)) { + $fields['data'] = serialize($data); + $fields['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); + else { + $fields['data'] = $data; + $fields['serialized'] = 0; } + db_merge('cache_update') + ->key(array('cid' => $cid)) + ->fields($fields) + ->execute(); } /** - * Retrieve data from the private update status cache table. + * Retrieves data from the private update status cache table. * * @param $cid * The cache ID to retrieve. + * * @return - * The data for the given cache ID, or NULL if the ID was not found. + * An array of data for the given cache ID, or NULL if the ID was not found. + * + * @see _update_cache_set() */ function _update_cache_get($cid) { - $cache = db_fetch_object(db_query("SELECT data, created, expire, serialized FROM {cache_update} WHERE cid = '%s'", $cid)); + $cache = db_query("SELECT data, created, expire, serialized FROM {cache_update} WHERE cid = :cid", array(':cid' => $cid))->fetchObject(); if (isset($cache->data)) { - $cache->data = db_decode_blob($cache->data); if ($cache->serialized) { $cache->data = unserialize($cache->data); } @@ -576,36 +807,77 @@ function _update_cache_get($cid) { } /** - * Invalidates specific cached data relating to update status. + * Returns an array of cache items with a given cache ID prefix. + * + * @param string $cid_prefix + * The cache ID prefix. + * + * @return + * Associative array of cache items, keyed by cache ID. + */ +function _update_get_cache_multiple($cid_prefix) { + $data = array(); + $result = db_select('cache_update') + ->fields('cache_update', array('cid', 'data', 'created', 'expire', 'serialized')) + ->condition('cache_update.cid', $cid_prefix . '::%', 'LIKE') + ->execute(); + foreach ($result as $cache) { + if ($cache) { + if ($cache->serialized) { + $cache->data = unserialize($cache->data); + } + $data[$cache->cid] = $cache; + } + } + return $data; +} + +/** + * Invalidates cached data relating to update status. * * @param $cid - * Optional cache ID of the record to clear from the private update module - * cache. If empty, all records will be cleared from the table. + * (optional) Cache ID of the record to clear from the private update module + * cache. If empty, all records will be cleared from the table except fetch + * tasks. Defaults to NULL. + * @param $wildcard + * (optional) If TRUE, cache IDs starting with $cid are deleted in addition to + * the exact cache ID specified by $cid. Defaults to FALSE. */ -function _update_cache_clear($cid = NULL) { +function _update_cache_clear($cid = NULL, $wildcard = FALSE) { if (empty($cid)) { - db_query("TRUNCATE TABLE {cache_update}"); + db_delete('cache_update') + // Clear everything except fetch task information because these are used + // to ensure that the fetch task queue items are not added multiple times. + ->condition('cid', 'fetch_task::%', 'NOT LIKE') + ->execute(); } else { - db_query("DELETE FROM {cache_update} WHERE cid = '%s'", $cid); + $query = db_delete('cache_update'); + if ($wildcard) { + $query->condition('cid', $cid . '%', 'LIKE'); + } + else { + $query->condition('cid', $cid); + } + $query->execute(); } } /** - * Implementation of hook_flush_caches(). + * Implements hook_flush_caches(). * - * Called from update.php (among others) to flush the caches. - * Since we're running update.php, we are likely to install a new version of - * something, in which case, we want to check for available update data again. - * However, because we have our own caching system, we need to directly clear - * the database table ourselves at this point and return nothing, for example, - * on sites that use memcache where cache_clear_all() won't know how to purge - * this data. + * Called from update.php (among others) to flush the caches. Since we're + * running update.php, we are likely to install a new version of something, in + * which case, we want to check for available update data again. However, + * because we have our own caching system, we need to directly clear the + * database table ourselves at this point and return nothing, for example, on + * sites that use memcache where cache_clear_all() won't know how to purge this + * data. * - * However, we only want to do this from update.php, since otherwise, we'd - * lose all the available update data on every cron run. So, we specifically - * check if the site is in MAINTENANCE_MODE == 'update' (which indicates - * update.php is running, not update module... alas for overloaded names). + * However, we only want to do this from update.php, since otherwise, we'd lose + * all the available update data on every cron run. So, we specifically check if + * the site is in MAINTENANCE_MODE == 'update' (which indicates update.php is + * running, not update module... alas for overloaded names). */ function update_flush_caches() { if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') { @@ -615,12 +887,107 @@ function update_flush_caches() { } /** - * Invalidates all cached data relating to update status. + * @} End of "defgroup update_status_cache". */ -function update_invalidate_cache() { - _update_cache_clear(); + +/** + * Returns a short unique identifier for this Drupal installation. + * + * @return + * An eight character string uniquely identifying this Drupal installation. + */ +function _update_manager_unique_identifier() { + $id = &drupal_static(__FUNCTION__, ''); + if (empty($id)) { + $id = substr(hash('sha256', drupal_get_hash_salt()), 0, 8); + } + return $id; } /** - * @} End of "defgroup update_status_cache". + * Returns the directory where update archive files should be extracted. + * + * @param $create + * (optional) Whether to attempt to create the directory if it does not + * already exist. Defaults to TRUE. + * + * @return + * The full path to the temporary directory where update file archives should + * be extracted. + */ +function _update_manager_extract_directory($create = TRUE) { + $directory = &drupal_static(__FUNCTION__, ''); + if (empty($directory)) { + $directory = 'temporary://update-extraction-' . _update_manager_unique_identifier(); + if ($create && !file_exists($directory)) { + mkdir($directory); + } + } + return $directory; +} + +/** + * Returns the directory where update archive files should be cached. + * + * @param $create + * (optional) Whether to attempt to create the directory if it does not + * already exist. Defaults to TRUE. + * + * @return + * The full path to the temporary directory where update file archives should + * be cached. + */ +function _update_manager_cache_directory($create = TRUE) { + $directory = &drupal_static(__FUNCTION__, ''); + if (empty($directory)) { + $directory = 'temporary://update-cache-' . _update_manager_unique_identifier(); + if ($create && !file_exists($directory)) { + mkdir($directory); + } + } + return $directory; +} + +/** + * Clears the temporary files and directories based on file age from disk. */ +function update_clear_update_disk_cache() { + // List of update module cache directories. Do not create the directories if + // they do not exist. + $directories = array( + _update_manager_cache_directory(FALSE), + _update_manager_extract_directory(FALSE), + ); + + // Search for files and directories in base folder only without recursion. + foreach ($directories as $directory) { + file_scan_directory($directory, '/.*/', array('callback' => 'update_delete_file_if_stale', 'recurse' => FALSE)); + } +} + +/** + * Deletes stale files and directories from the update manager disk cache. + * + * Files and directories older than 6 hours and development snapshots older than + * 5 minutes are considered stale. We only cache development snapshots for 5 + * minutes since otherwise updated snapshots might not be downloaded as + * expected. + * + * When checking file ages, we need to use the ctime, not the mtime + * (modification time) since many (all?) tar implementations go out of their way + * to set the mtime on the files they create to the timestamps recorded in the + * tarball. We want to see the last time the file was changed on disk, which is + * left alone by tar and correctly set to the time the archive file was + * unpacked. + * + * @param $path + * A string containing a file path or (streamwrapper) URI. + */ +function update_delete_file_if_stale($path) { + if (file_exists($path)) { + $filectime = filectime($path); + if (REQUEST_TIME - $filectime > DRUPAL_MAXIMUM_TEMP_FILE_AGE || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) { + file_unmanaged_delete_recursive($path); + } + } +} diff -rup /Users/webchick/Sites/6.x/modules/update/update.report.inc /Users/webchick/Sites/7.x/modules/update/update.report.inc --- /Users/webchick/Sites/6.x/modules/update/update.report.inc 2014-01-11 21:40:30.000000000 -0800 +++ /Users/webchick/Sites/7.x/modules/update/update.report.inc 2012-12-31 14:20:25.000000000 -0800 @@ -6,32 +6,38 @@ */ /** - * Menu callback. Generate a page about the update status of projects. + * Page callback: Generates a page about the update status of projects. + * + * @see update_menu() */ function update_status() { if ($available = update_get_available(TRUE)) { module_load_include('inc', 'update', 'update.compare'); $data = update_calculate_project_data($available); - return theme('update_report', $data); + return theme('update_report', array('data' => $data)); } else { - return theme('update_report', _update_no_data()); + return theme('update_report', array('data' => _update_no_data())); } } /** - * Theme project status report. + * Returns HTML for the project status report. + * + * @param array $variables + * An associative array containing: + * - data: An array of data about each project's status. * * @ingroup themeable */ -function theme_update_report($data) { +function theme_update_report($variables) { + $data = $variables['data']; + $last = variable_get('update_last_check', 0); - $output = '
'. ($last ? t('Last checked: @time ago', array('@time' => format_interval(time() - $last))) : t('Last checked: never')); - $output .= ' ('. l(t('Check manually'), 'admin/reports/updates/check') .')'; - $output .= "
\n"; + $output = theme('update_last_check', array('last' => $last)); if (!is_array($data)) { - $output .= '

'. $data .'

'; + $output .= '

' . $data . '

'; return $output; } @@ -40,53 +46,45 @@ function theme_update_report($data) { $notification_level = variable_get('update_notification_threshold', 'all'); + // Create an array of status values keyed by module or theme name, since + // we'll need this while generating the report if we have to cross reference + // anything (e.g. subthemes which have base themes missing an update). + foreach ($data as $project) { + foreach ($project['includes'] as $key => $name) { + $status[$key] = $project['status']; + } + } + foreach ($data as $project) { switch ($project['status']) { case UPDATE_CURRENT: $class = 'ok'; - $icon = theme('image', 'misc/watchdog-ok.png', t('ok'), t('ok')); + $icon = theme('image', array('path' => 'misc/watchdog-ok.png', 'width' => 18, 'height' => 18, 'alt' => t('ok'), 'title' => t('ok'))); break; case UPDATE_UNKNOWN: + case UPDATE_FETCH_PENDING: case UPDATE_NOT_FETCHED: $class = 'unknown'; - $icon = theme('image', 'misc/watchdog-warning.png', t('warning'), t('warning')); + $icon = theme('image', array('path' => 'misc/watchdog-warning.png', 'width' => 18, 'height' => 18, 'alt' => t('warning'), 'title' => t('warning'))); break; case UPDATE_NOT_SECURE: case UPDATE_REVOKED: case UPDATE_NOT_SUPPORTED: $class = 'error'; - $icon = theme('image', 'misc/watchdog-error.png', t('error'), t('error')); + $icon = theme('image', array('path' => 'misc/watchdog-error.png', 'width' => 18, 'height' => 18, 'alt' => t('error'), 'title' => t('error'))); break; case UPDATE_NOT_CHECKED: case UPDATE_NOT_CURRENT: default: $class = 'warning'; - $icon = theme('image', 'misc/watchdog-warning.png', t('warning'), t('warning')); + $icon = theme('image', array('path' => 'misc/watchdog-warning.png', 'width' => 18, 'height' => 18, 'alt' => t('warning'), 'title' => t('warning'))); break; } $row = '
'; - switch ($project['status']) { - case UPDATE_NOT_SECURE: - $row .= ''. t('Security update required!') .''; - break; - case UPDATE_REVOKED: - $row .= ''. t('Revoked!') .''; - break; - case UPDATE_NOT_SUPPORTED: - $row .= ''. t('Not supported!') .''; - break; - case UPDATE_NOT_CURRENT: - $row .= ''. t('Update available') .''; - break; - case UPDATE_CURRENT: - $row .= ''. t('Up to date') .''; - break; - default: - $row .= check_plain($project['reason']); - break; - } - $row .= ''. $icon .''; + $status_label = theme('update_status_label', array('status' => $project['status'])); + $row .= !empty($status_label) ? $status_label : check_plain($project['reason']); + $row .= '' . $icon . ''; $row .= "
\n"; $row .= '
'; @@ -101,14 +99,15 @@ function theme_update_report($data) { else { $row .= check_plain($project['name']); } - $row .= ' '. check_plain($project['existing_version']); + $row .= ' ' . check_plain($project['existing_version']); if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) { - $row .= ' ('. format_date($project['datestamp'], 'custom', 'Y-M-d') .')'; + $row .= ' (' . format_date($project['datestamp'], 'custom', 'Y-M-d') . ')'; } $row .= "
\n"; - $row .= "
\n"; - + $versions_inner = ''; + $security_class = array(); + $version_class = array(); if (isset($project['recommended'])) { if ($project['status'] != UPDATE_CURRENT || $project['existing_version'] !== $project['recommended']) { @@ -117,61 +116,63 @@ function theme_update_report($data) { // 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'; + $security_class[] = 'version-recommended'; + $security_class[] = 'version-recommended-strong'; } else { - $security_class = ''; - $version_class = 'version-recommended'; + $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' - && isset($project['dev_version']) - && $project['latest_version'] !== $project['dev_version'] - && $project['recommended'] !== $project['dev_version']) + && isset($project['dev_version']) + && $project['latest_version'] !== $project['dev_version'] + && $project['recommended'] !== $project['dev_version']) || (isset($project['security updates'][0]) - && $project['recommended'] !== $project['security updates'][0]) + && $project['recommended'] !== $project['security updates'][0]) ) { - $version_class .= ' version-recommended-strong'; + $version_class[] = 'version-recommended-strong'; } - $row .= theme('update_version', $project['releases'][$project['recommended']], t('Recommended version:'), $version_class); + $versions_inner .= theme('update_version', array('version' => $project['releases'][$project['recommended']], 'tag' => t('Recommended version:'), 'class' => $version_class)); } // Now, print any security updates. if (!empty($project['security updates'])) { + $security_class[] = 'version-security'; foreach ($project['security updates'] as $security_update) { - $row .= theme('update_version', $security_update, t('Security update:'), 'version-security'. $security_class); + $versions_inner .= theme('update_version', array('version' => $security_update, 'tag' => t('Security update:'), 'class' => $security_class)); } } } if ($project['recommended'] !== $project['latest_version']) { - $row .= theme('update_version', $project['releases'][$project['latest_version']], t('Latest version:'), 'version-latest'); + $versions_inner .= theme('update_version', array('version' => $project['releases'][$project['latest_version']], 'tag' => t('Latest version:'), 'class' => array('version-latest'))); } if ($project['install_type'] == 'dev' && $project['status'] != UPDATE_CURRENT && isset($project['dev_version']) && $project['recommended'] !== $project['dev_version']) { - $row .= theme('update_version', $project['releases'][$project['dev_version']], t('Development version:'), 'version-latest'); + $versions_inner .= theme('update_version', array('version' => $project['releases'][$project['dev_version']], 'tag' => t('Development version:'), 'class' => array('version-latest'))); } } if (isset($project['also'])) { foreach ($project['also'] as $also) { - $row .= theme('update_version', $project['releases'][$also], t('Also available:'), 'version-also-available'); + $versions_inner .= theme('update_version', array('version' => $project['releases'][$also], 'tag' => t('Also available:'), 'class' => array('version-also-available'))); } } - $row .= "
\n"; // versions div. - + if (!empty($versions_inner)) { + $row .= "
\n" . $versions_inner . "
\n"; + } $row .= "
\n"; if (!empty($project['extra'])) { - $row .= '
'."\n"; + $row .= '
' . "\n"; foreach ($project['extra'] as $key => $value) { - $row .= '
'; - $row .= check_plain($value['label']) .': '; - $row .= theme('placeholder', $value['data']); + $row .= '
'; + $row .= check_plain($value['label']) . ': '; + $row .= drupal_placeholder($value['data']); $row .= "
\n"; } $row .= "
\n"; // extra div. @@ -179,26 +180,44 @@ function theme_update_report($data) { $row .= '
'; sort($project['includes']); - $row .= t('Includes: %includes', array('%includes' => implode(', ', $project['includes']))); + if (!empty($project['disabled'])) { + sort($project['disabled']); + // Make sure we start with a clean slate for each project in the report. + $includes_items = array(); + $row .= t('Includes:'); + $includes_items[] = t('Enabled: %includes', array('%includes' => implode(', ', $project['includes']))); + $includes_items[] = t('Disabled: %disabled', array('%disabled' => implode(', ', $project['disabled']))); + $row .= theme('item_list', array('items' => $includes_items)); + } + else { + $row .= t('Includes: %includes', array('%includes' => implode(', ', $project['includes']))); + } $row .= "
\n"; if (!empty($project['base_themes'])) { $row .= '
'; - sort($project['base_themes']); - // We use !dependencies and manually call theme('placeholder') here to - // avoid breakding the D6 string freeze. This identical string is - // already in modules/system/system.admin.inc. - $row .= t('Depends on: !dependencies', array('!dependencies' => theme('placeholder', implode(', ', $project['base_themes'])))); + asort($project['base_themes']); + $base_themes = array(); + foreach ($project['base_themes'] as $base_key => $base_theme) { + switch ($status[$base_key]) { + case UPDATE_NOT_SECURE: + case UPDATE_REVOKED: + case UPDATE_NOT_SUPPORTED: + $base_themes[] = t('%base_theme (!base_label)', array('%base_theme' => $base_theme, '!base_label' => theme('update_status_label', array('status' => $status[$base_key])))); + break; + + default: + $base_themes[] = drupal_placeholder($base_theme); + } + } + $row .= t('Depends on: !basethemes', array('!basethemes' => implode(', ', $base_themes))); $row .= "
\n"; } if (!empty($project['sub_themes'])) { $row .= '
'; sort($project['sub_themes']); - // We use !required and manually call theme('placeholder') here to avoid - // breakding the D6 string freeze. This identical string is already in - // modules/system/system.admin.inc. - $row .= t('Required by: !required', array('!required' => theme('placeholder', implode(', ', $project['sub_themes'])))); + $row .= t('Required by: %subthemes', array('%subthemes' => implode(', ', $project['sub_themes']))); $row .= "
\n"; } @@ -209,7 +228,7 @@ function theme_update_report($data) { } $row_key = isset($project['title']) ? drupal_strtolower($project['title']) : drupal_strtolower($project['name']); $rows[$project['project_type']][$row_key] = array( - 'class' => $class, + 'class' => array($class), 'data' => array($row), ); } @@ -218,33 +237,77 @@ function theme_update_report($data) { 'core' => t('Drupal core'), 'module' => t('Modules'), 'theme' => t('Themes'), - 'disabled-module' => t('Disabled modules'), - 'disabled-theme' => t('Disabled themes'), + 'module-disabled' => t('Disabled modules'), + 'theme-disabled' => t('Disabled themes'), ); foreach ($project_types as $type_name => $type_label) { if (!empty($rows[$type_name])) { ksort($rows[$type_name]); - $output .= "\n

". $type_label ."

\n"; - $output .= theme('table', $header, $rows[$type_name], array('class' => 'update')); + $output .= "\n

" . $type_label . "

\n"; + $output .= theme('table', array('header' => $header, 'rows' => $rows[$type_name], 'attributes' => array('class' => array('update')))); } } - drupal_add_css(drupal_get_path('module', 'update') .'/update.css'); + drupal_add_css(drupal_get_path('module', 'update') . '/update.css'); return $output; } /** - * Theme the version display of a project. + * Returns HTML for a label to display for a project's update status. + * + * @param array $variables + * An associative array containing: + * - status: The integer code for a project's current update status. + * + * @see update_calculate_project_data() + * @ingroup themeable + */ +function theme_update_status_label($variables) { + switch ($variables['status']) { + case UPDATE_NOT_SECURE: + return '' . t('Security update required!') . ''; + + case UPDATE_REVOKED: + return '' . t('Revoked!') . ''; + + case UPDATE_NOT_SUPPORTED: + return '' . t('Not supported!') . ''; + + case UPDATE_NOT_CURRENT: + return '' . t('Update available') . ''; + + case UPDATE_CURRENT: + return '' . t('Up to date') . ''; + + } +} + +/** + * Returns HTML for the version display of a project. + * + * @param array $variables + * An associative array containing: + * - version: An array of data about the latest released version, containing: + * - version: The version number. + * - release_link: The URL for the release notes. + * - date: The date of the release. + * - download_link: The URL for the downloadable file. + * - tag: The title of the project. + * - class: A string containing extra classes for the wrapping table. * * @ingroup themeable */ -function theme_update_version($version, $tag, $class) { +function theme_update_version($variables) { + $version = $variables['version']; + $tag = $variables['tag']; + $class = implode(' ', $variables['class']); + $output = ''; - $output .= ''; + $output .= '
'; $output .= ''; - $output .= '\n"; + $output .= '\n"; $output .= '\n"; $output .= ''; $output .= ''; $output .= "
'. $tag ."' . $tag . "'; $output .= l($version['version'], $version['release_link']); - $output .= ' ('. format_date($version['date'], 'custom', 'Y-M-d') .')'; + $output .= ' (' . format_date($version['date'], 'custom', 'Y-M-d') . ')'; $output .= "
\n"; diff -rup /Users/webchick/Sites/6.x/modules/update/update.settings.inc /Users/webchick/Sites/7.x/modules/update/update.settings.inc --- /Users/webchick/Sites/6.x/modules/update/update.settings.inc 2013-02-19 13:25:56.000000000 -0800 +++ /Users/webchick/Sites/7.x/modules/update/update.settings.inc 2012-12-31 14:20:25.000000000 -0800 @@ -6,20 +6,13 @@ */ /** - * Form builder for the update settings tab. + * Form constructor for the update settings form. + * + * @see update_settings_validate() + * @see update_settings_submit() + * @ingroup forms */ -function update_settings() { - $form = array(); - - $notify_emails = variable_get('update_notify_emails', array()); - $form['update_notify_emails'] = array( - '#type' => 'textarea', - '#title' => t('E-mail addresses to notify when updates are available'), - '#rows' => 4, - '#default_value' => implode("\n", $notify_emails), - '#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via e-mail. Put each address on a separate line. If blank, no e-mails will be sent.'), - ); - +function update_settings($form) { $form['update_check_frequency'] = array( '#type' => 'radios', '#title' => t('Check for updates'), @@ -31,6 +24,21 @@ function update_settings() { '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'), ); + $form['update_check_disabled'] = array( + '#type' => 'checkbox', + '#title' => t('Check for updates of disabled modules and themes'), + '#default_value' => variable_get('update_check_disabled', FALSE), + ); + + $notify_emails = variable_get('update_notify_emails', array()); + $form['update_notify_emails'] = array( + '#type' => 'textarea', + '#title' => t('E-mail addresses to notify when updates are available'), + '#rows' => 4, + '#default_value' => implode("\n", $notify_emails), + '#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via e-mail. Put each address on a separate line. If blank, no e-mails will be sent.'), + ); + $form['update_notification_threshold'] = array( '#type' => 'radios', '#title' => t('E-mail notification threshold'), @@ -43,7 +51,7 @@ function update_settings() { ); $form = system_settings_form($form); - // Custom valiation callback for the email notification setting. + // Custom validation callback for the email notification setting. $form['#validate'][] = 'update_settings_validate'; // We need to call our own submit callback first, not the one from // system_settings_form(), so that we can process and save the emails. @@ -53,9 +61,11 @@ function update_settings() { } /** - * Validation callback for the settings form. + * Form validation handler for update_settings(). * - * Validates the email addresses and ensures the field is formatted correctly. + * Validates the e-mail addresses and ensures the field is formatted correctly. + * + * @see update_settings_submit() */ function update_settings_validate($form, &$form_state) { if (!empty($form_state['values']['update_notify_emails'])) { @@ -85,23 +95,34 @@ function update_settings_validate($form, } /** - * Submit handler for the settings tab. + * Form submission handler for update_settings(). + * + * Also invalidates the cache of available updates if the "Check for updates of + * disabled modules and themes" setting is being changed. The available updates + * report needs to refetch available update data after this setting changes or + * it would show misleading things (e.g., listing the disabled projects on the + * site with the "No available releases found" warning). + * + * @see update_settings_validate() */ function update_settings_submit($form, $form_state) { $op = $form_state['values']['op']; - if ($op == t('Reset to defaults')) { - unset($form_state['notify_emails']); + if (empty($form_state['notify_emails'])) { + variable_del('update_notify_emails'); } else { - if (empty($form_state['notify_emails'])) { - variable_del('update_notify_emails'); - } - else { - variable_set('update_notify_emails', $form_state['notify_emails']); - } - unset($form_state['notify_emails']); - unset($form_state['values']['update_notify_emails']); + variable_set('update_notify_emails', $form_state['notify_emails']); } + unset($form_state['notify_emails']); + unset($form_state['values']['update_notify_emails']); + + // See if the update_check_disabled setting is being changed, and if so, + // invalidate all cached update status data. + $check_disabled = variable_get('update_check_disabled', FALSE); + if ($form_state['values']['update_check_disabled'] != $check_disabled) { + _update_cache_clear(); + } + system_settings_form_submit($form, $form_state); } Only in /Users/webchick/Sites/7.x/modules/update: update.test