diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-09-07 15:43:55 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-09-07 15:43:55 +0000 |
commit | 95e95bfbf20e993c1aaeeeb580649075f2619e5c (patch) | |
tree | e4ef04c8e52ae35fe713e6187d682afc771042b7 /includes/update.inc | |
parent | f73040e18b1bde3421e9971d99b39ee3fa39abe5 (diff) | |
download | brdo-95e95bfbf20e993c1aaeeeb580649075f2619e5c.tar.gz brdo-95e95bfbf20e993c1aaeeeb580649075f2619e5c.tar.bz2 |
- Patch #394268 by Crell, sun, yched: changed DIE update_sql() DIE!.
Diffstat (limited to 'includes/update.inc')
-rw-r--r-- | includes/update.inc | 79 |
1 files changed, 67 insertions, 12 deletions
diff --git a/includes/update.inc b/includes/update.inc index 439864311..f7427a8d3 100644 --- a/includes/update.inc +++ b/includes/update.inc @@ -273,7 +273,7 @@ function update_fix_d7_requirements() { * * Install profiles are now treated as modules by Drupal, and have an upgrade path * based on their schema version in the system table. - * + * * The install profile will be set to schema_version 0, as it has already been * installed. Any other hook_update_N functions provided by the install profile * will be run by update.php. @@ -365,13 +365,31 @@ function update_parse_db_url($db_url) { * Perform one update and store the results which will later be displayed on * the finished page. * - * An update function can force the current and all later updates for this - * module to abort by returning a $ret array with an element like: - * $ret['#abort'] = array('success' => FALSE, 'query' => 'What went wrong'); - * The schema version will not be updated in this case, and all the - * aborted updates will continue to appear on update.php as updates that + * If an update function completes successfully, it should return a message + * as a string indicating success, for example: + * @code + * return t('New index added successfully.'); + * @endcode + * + * Alternatively, it may return nothing. In that case, no message + * will be displayed at all. + * + * If it fails for whatever reason, it should throw an instance of + * DrupalUpdateException with an appropriate error message, for example: + * @code + * throw new DrupalUpdateException(t('Description of what went wrong')); + * @endcode + * + * If an exception is thrown, the current and all later updates for this module + * will be aborted. The schema version will not be updated in this case, and all + * the aborted updates will continue to appear on update.php as updates that * have not yet been run. * + * If an update function needs to be re-run as part of a batch process, it + * should accept the $sandbox array by reference as its first parameter + * and set the #finished property to the percentage completed that it is, as a + * fraction of 1. + * * @param $module * The module whose update will be run. * @param $number @@ -386,16 +404,49 @@ function update_do_one($module, $number, &$context) { return; } + if (!isset($context['log'])) { + $context['log'] = variable_get('update_log_queries', 0); + } + + $ret = array(); $function = $module . '_update_' . $number; if (function_exists($function)) { - $ret = $function($context['sandbox']); + try { + if ($context['log']) { + Database::startLog($function); + } + $ret['results']['query'] = $function($context['sandbox']); + $ret['results']['success'] = TRUE; + + // @TODO Remove this block after all updates have been converted to + // return only strings. + if (is_array($ret['results']['query'])) { + $ret = $ret['results']['query']; + } + } + // @TODO We may want to do different error handling for different exception + // types, but for now we'll just print the message. + catch (Exception $e) { + $ret['#abort'] = array('success' => FALSE, 'query' => $e->getMessage()); + } + + if ($context['log']) { + $ret['queries'] = Database::getLog($function); + } } + // @TODO Remove this block after all updates have been converted to return + // only strings. if (isset($ret['#finished'])) { $context['finished'] = $ret['#finished']; unset($ret['#finished']); } + if (isset($context['sandbox']['#finished'])) { + $context['finished'] = $context['sandbox']['#finished']; + unset($context['sandbox']['#finished']); + } + if (!isset($context['results'][$module])) { $context['results'][$module] = array(); } @@ -407,17 +458,21 @@ function update_do_one($module, $number, &$context) { if (!empty($ret['#abort'])) { $context['results'][$module]['#abort'] = TRUE; } + // Record the schema update if it was completed successfully. if ($context['finished'] == 1 && empty($context['results'][$module]['#abort'])) { drupal_set_installed_schema_version($module, $number); - // Conserve memory and avoid errors by resetting all static variables. - drupal_static_reset(); } $context['message'] = 'Updating ' . check_plain($module) . ' module'; } /** + * @class Exception class used to throw error if a module update fails. + */ +class DrupalUpdateException extends Exception { } + +/** * Start the database update batch process. * * @param $start @@ -518,7 +573,7 @@ function update_finished($success, $results, $operations) { function update_get_update_list() { // Make sure that the system module is first in the list of updates. $ret = array('system' => array()); - + $modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE); foreach ($modules as $module => $schema_version) { $pending = array(); @@ -532,7 +587,7 @@ function update_get_update_list() { $ret[$module]['warning'] = '<em>' . $module . '</em> module can not be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update <em>' . $module . '</em> module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.'; continue; } - + $updates = drupal_map_assoc($updates); foreach (array_keys($updates) as $update) { if ($update > $schema_version) { @@ -550,7 +605,7 @@ function update_get_update_list() { } } } - + if (empty($ret['system'])) { unset($ret['system']); } |