Index: system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.722 diff -u -p -r1.722 system.module --- system/system.module 5 Jul 2009 18:00:10 -0000 1.722 +++ system/system.module 16 Jul 2009 09:58:11 -0000 @@ -1268,27 +1268,28 @@ function system_filetransfer_backend_for function _system_filetransfer_backend_form_common() { $form = array(); - $form['hostname'] = array ( + $form['hostname'] = array( '#type' => 'textfield', '#title' => t('Host'), '#default_value' => 'localhost', ); - - $form['port'] = array ( + + $form['port'] = array( '#type' => 'textfield', '#title' => t('Port'), '#default_value' => NULL, ); - - $form['username'] = array ( + + $form['username'] = array( '#type' => 'textfield', '#title' => t('Username'), ); - - $form['password'] = array ( + + $form['password'] = array( '#type' => 'password', '#title' => t('Password'), '#description' => t('This is not saved in the database and is only used to test the connection'), + '#filetransfer_save' => FALSE, ); return $form; Index: update/update.css =================================================================== RCS file: /cvs/drupal/drupal/modules/update/update.css,v retrieving revision 1.5 diff -u -p -r1.5 update.css --- update/update.css 29 Apr 2009 03:57:21 -0000 1.5 +++ update/update.css 16 Jul 2009 09:58:11 -0000 @@ -1,110 +1,10 @@ -/* $Id: update.css,v 1.5 2009/04/29 03:57:21 webchick Exp $ */ +/* $Id$ */ -.update .project { - font-weight: bold; - font-size: 110%; - padding-left: .25em; /* LTR */ - height: 22px; -} - -.update .version-status { - float: right; /* LTR */ - padding-right: 10px; /* LTR */ - font-size: 110%; - height: 20px; -} - -.update .version-status .icon { - padding-left: .5em; /* LTR */ -} - -.update .version-date { - white-space: nowrap; -} - -.update .info { - margin: 0; - padding: 1em 1em .25em 1em; -} - -.update tr td { - border-top: 1px solid #ccc; - border-bottom: 1px solid #ccc; -} - -.update tr.error { +table tbody tr.update-security, +table tbody tr.update-unsupported { background: #fcc; } -.update tr.error .version-recommended { - background: #fdd; -} - -.update tr.ok { - background: #dfd; -} - -.update tr.warning { - background: #ffd; -} - -.update tr.warning .version-recommended { - background: #ffe; -} - -.current-version, .new-version { - direction: ltr; /* Note: version numbers should always be LTR. */ -} - -.update tr.unknown { - background: #ddd; -} - -table.update, -.update table.version { - width: 100%; - margin-top: .5em; -} - -.update table.version tbody { - border: none; -} - -.update table.version tr, -.update table.version td { - line-height: .9em; - padding: 0; - margin: 0; - border: none; -} - -.update table.version .version-title { - padding-left: 1em; /* LTR */ - width: 14em; -} - -.update table.version .version-details { - padding-right: .5em; /* LTR */ -} - -.update table.version .version-links { - text-align: right; /* LTR */ - padding-right: 1em; /* LTR */ -} - -.update table.version-security .version-title { - color: #970F00; -} - -.update table.version-recommended-strong .version-title { - font-weight: bold; -} - -.update .security-error { - font-weight: bold; - color: #970F00; -} - -.update .check-manually { - padding-left: 1em; /* LTR */ -} +th.update-project-name { + width: 50%; +} \ No newline at end of file Index: update/update.info =================================================================== RCS file: /cvs/drupal/drupal/modules/update/update.info,v retrieving revision 1.5 diff -u -p -r1.5 update.info --- update/update.info 11 Oct 2008 02:33:12 -0000 1.5 +++ update/update.info 16 Jul 2009 09:58:11 -0000 @@ -7,6 +7,7 @@ core = 7.x files[] = update.module files[] = update.compare.inc files[] = update.fetch.inc -files[] = update.report.inc +files[] = update.admin.inc files[] = update.settings.inc files[] = update.install +files[] = update.js Index: update/update.module =================================================================== RCS file: /cvs/drupal/drupal/modules/update/update.module,v retrieving revision 1.37 diff -u -p -r1.37 update.module --- update/update.module 8 Jun 2009 05:00:11 -0000 1.37 +++ update/update.module 16 Jul 2009 09:58:12 -0000 @@ -69,8 +69,7 @@ function update_help($path, $arg) { case 'admin/reports/updates': global $base_url; $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')) . '

'; - $output .= '

' . t('Each time Drupal core or a contributed module or theme is updated, it is important that update.php is run.', array('@update-php' => url($base_url . '/update.php', array('external' => TRUE)))) . '

'; + return $output; case 'admin/build/themes': case 'admin/build/modules': @@ -129,7 +128,8 @@ function update_menu() { $items['admin/reports/updates'] = array( 'title' => 'Available updates', 'description' => 'Get a status report about available updates for your installed modules and themes.', - 'page callback' => 'update_status', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('update_update_form'), 'access arguments' => array('administer site configuration'), 'weight' => 10, ); @@ -155,15 +155,9 @@ function update_menu() { */ function update_theme() { return array( - 'update_settings' => array( + 'update_available_updates_form' => array( 'arguments' => array('form' => NULL), ), - 'update_report' => array( - 'arguments' => array('data' => NULL), - ), - 'update_version' => array( - 'arguments' => array('version' => NULL, 'tag' => NULL, 'class' => NULL), - ), ); } @@ -632,3 +626,218 @@ function update_flush_caches() { /** * @} End of "defgroup update_status_cache". */ + +/** + * Get the latest version of a project. + */ +function _update_get_latest_version($name) { + if ($available = update_get_available(FALSE)) { + module_load_include('inc', 'update', 'update.compare'); + $extension_data = update_calculate_project_data($available); + $project = $extension_data[$name]; + return $project['releases'][$project['latest_version']]; + } +} + +/** + * Get a file from the server, or if it was already downloaded, get the local + * path to the file. + * + * @param $url + * The URL of the file on the server. + */ +function update_get_file($url) { + // Get each of the specified files. + $parsed_url = parse_url($url); + $local = file_directory_temp() . '/update-cache/' . basename($parsed_url['path']); + if (!file_exists(file_directory_temp() . '/update-cache/')) { + mkdir(file_directory_temp() . '/update-cache/'); + } + // Check the cache and download the file if needed. + if (!file_exists($local)) { + return system_retrieve_file($url, $local); + } + else { + return $local; + } +} + +/** + * Untar a file, using the Archive_Tar class. + */ +function update_untar($file) { + $extraction_dir = file_directory_temp() . '/update-extraction'; + if (!file_exists($extraction_dir)) { + mkdir($extraction_dir); + } + $archive_tar = new Archive_Tar($file); + return $archive_tar->extract($extraction_dir); +} + +/** + * Download an extension from the server and put it in a temporary cache. + */ +function update_get_extension($extension_name, &$context) { + if (!isset($context['sandbox']['started'])) { + $context['sandbox']['started'] = TRUE; + $context['message'] = t('Downloading %extension', array('%extension' => $extension_name)); + $context['finished'] = 0; + return; + } + $latest_version = _update_get_latest_version($extension_name); + if (update_get_file($latest_version['download_link'])) { + watchdog('update', t('Downloaded %extension to %local_cache', array('%extension' => $extension_name, '%local_cache' => $local_cache))); + } + else { + $context['success'] = FALSE; + $content['results'][] = t('Failed to download %extension', array('%extension' => $extension_name)); + } + + $context['finished'] = 1; +} + +/** + * Copy an extension to it's proper place. + */ +function update_copy_extension($extension_name, $filetransfer, &$context) { + if (!isset($context['sandbox']['starting'])) { + $context['sandbox']['starting'] = 1; + $context['message'] = t('Copying %extension to server', array('%extension' => $extension_name)); + $context['finished'] = 0; + return; + } + + $latest_version = _update_get_latest_version($extension_name); + $local_cache = update_get_file($latest_version['download_link']); + + if ($extension_info = _update_get_extension_type_and_location($extension_name)) { + // This is an update + $is_install = FALSE; + $location = $extension_info['location']; + } else { + //This is a fresh install, not an update + $location = variable_get('update_default_module_location', 'sites/all/modules') . '/' . $extension_name; + $is_install = TRUE; + //throw new Exception(t("Unable to find %extension_name", array('%extension_name' => $extension_destination_dir))); + } + + $extension_destination_dir = DRUPAL_ROOT . '/' . $location; + + if (update_untar($local_cache)) { + $extension_source_dir = file_directory_temp() . '/update-extraction/' . $extension_name; + } + try { + if (!$is_install) { + $filetransfer->removeDirectory($extension_destination_dir); + } + $filetransfer->copyDirectory($extension_source_dir, $extension_destination_dir); + } + catch (Exception $e) { + drupal_set_message(t($e->getMessage(), $e->arguments), 'error'); + // Some better error handling is needed, but batch API doesn't seem to support any. + throw $e; + } + $context['finished'] = 1; +} + +/** + * Helper function, returns a an associative array of an extension's type and + * location returns false on failure. + */ +function _update_get_extension_type_and_location($name) { + foreach (array('module', 'theme') as $type) { + if ($dir = drupal_get_path($type, $name)) { + return array('type' => $type, 'location' => $dir); + } + } + return FALSE; +} + +/** + * Set the batch to run the update functions. + */ +function update_update_extensions($projects, &$context) { + $operations = array(); + include_once './update.php'; + + foreach (_update_get_schema_updates($project) as $update) { + $operations[] = array('update_do_one', array($project, $update)); + } + + $batch = array( + 'title' => t('Installing updates'), + 'init_message' => t('Preparing update operation'), + 'operations' => $operations, + 'finished' => 'update_batch_finished', + ); + batch_set($batch); +} + +/** + * Run a single update. This is a wrapper around update_do_one, which includes + * the files needed. + * + * @see update_do_one + */ +function update_run_update($project, $update, &$context) { + include_once './update.php'; + module_load_include('install', $project); + update_do_one($project, $update, $context); +} + +/** + * Batch callback for when the batch is finished. + */ +function update_batch_finished($success, $results) { + if ($success) { + variable_set('site_offline', FALSE); + } + $_SESSION['update_batch_results']['success'] = $success; + $_SESSION['update_batch_results']['messages'] = $results; +} + +/** + * Get a filetransfer class. + * + * @param $method + * The filetransfer method to get the class for. + * @param $overrides + * A set of overrides over the defaults. + */ +function update_get_filetransfer($method, $overrides = array()) { + // Fire up the connection class + $settings = variable_get("update_filetransfer_connection_settings_" . $method, array()); + $settings = array_merge($settings, $overrides); + $available_backends = module_invoke_all('filetransfer_backends'); + $filetransfer = call_user_func_array($available_backends[$method]['class'] . '::factory', array(DRUPAL_ROOT, $settings)); + return $filetransfer; +} + +/** + * Returns the available updates for a given module in an array + * + * @param $project + * The name of the module. + */ +function _update_get_schema_updates($project) { + list($type, $location) = _update_get_extension_type_and_location($project); + if ($type != 'module') { + return array(); + } + module_load_include('install', $project); + + if (!$updates = drupal_get_schema_versions($project)) { + return array(); + } + $updates_to_run = array(); + $version = drupal_get_installed_schema_version($project, FALSE); + $max_version = max($updates); + if ($version < $max_version) { + foreach ($updates as $update) { + if ($update > $version) { + $updates_to_run[] = $update; + } + } + } + return $updates_to_run; +}