- Patch #394268 by Crell, sun, yched: changed DIE update_sql() DIE!.
parent
f73040e18b
commit
95e95bfbf2
|
@ -365,13 +365,31 @@ function update_parse_db_url($db_url) {
|
||||||
* Perform one update and store the results which will later be displayed on
|
* Perform one update and store the results which will later be displayed on
|
||||||
* the finished page.
|
* the finished page.
|
||||||
*
|
*
|
||||||
* An update function can force the current and all later updates for this
|
* If an update function completes successfully, it should return a message
|
||||||
* module to abort by returning a $ret array with an element like:
|
* as a string indicating success, for example:
|
||||||
* $ret['#abort'] = array('success' => FALSE, 'query' => 'What went wrong');
|
* @code
|
||||||
* The schema version will not be updated in this case, and all the
|
* return t('New index added successfully.');
|
||||||
* aborted updates will continue to appear on update.php as updates that
|
* @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.
|
* 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
|
* @param $module
|
||||||
* The module whose update will be run.
|
* The module whose update will be run.
|
||||||
* @param $number
|
* @param $number
|
||||||
|
@ -386,16 +404,49 @@ function update_do_one($module, $number, &$context) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$function = $module . '_update_' . $number;
|
if (!isset($context['log'])) {
|
||||||
if (function_exists($function)) {
|
$context['log'] = variable_get('update_log_queries', 0);
|
||||||
$ret = $function($context['sandbox']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ret = array();
|
||||||
|
$function = $module . '_update_' . $number;
|
||||||
|
if (function_exists($function)) {
|
||||||
|
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'])) {
|
if (isset($ret['#finished'])) {
|
||||||
$context['finished'] = $ret['#finished'];
|
$context['finished'] = $ret['#finished'];
|
||||||
unset($ret['#finished']);
|
unset($ret['#finished']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($context['sandbox']['#finished'])) {
|
||||||
|
$context['finished'] = $context['sandbox']['#finished'];
|
||||||
|
unset($context['sandbox']['#finished']);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isset($context['results'][$module])) {
|
if (!isset($context['results'][$module])) {
|
||||||
$context['results'][$module] = array();
|
$context['results'][$module] = array();
|
||||||
}
|
}
|
||||||
|
@ -407,16 +458,20 @@ function update_do_one($module, $number, &$context) {
|
||||||
if (!empty($ret['#abort'])) {
|
if (!empty($ret['#abort'])) {
|
||||||
$context['results'][$module]['#abort'] = TRUE;
|
$context['results'][$module]['#abort'] = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the schema update if it was completed successfully.
|
// Record the schema update if it was completed successfully.
|
||||||
if ($context['finished'] == 1 && empty($context['results'][$module]['#abort'])) {
|
if ($context['finished'] == 1 && empty($context['results'][$module]['#abort'])) {
|
||||||
drupal_set_installed_schema_version($module, $number);
|
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';
|
$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.
|
* Start the database update batch process.
|
||||||
*
|
*
|
||||||
|
|
19
update.php
19
update.php
|
@ -140,23 +140,28 @@ function update_results_page() {
|
||||||
// Output a list of queries executed
|
// Output a list of queries executed
|
||||||
if (!empty($_SESSION['update_results'])) {
|
if (!empty($_SESSION['update_results'])) {
|
||||||
$output .= '<div id="update-results">';
|
$output .= '<div id="update-results">';
|
||||||
$output .= '<h2>The following queries were executed</h2>';
|
$output .= '<h2>The following updates returned messages</h2>';
|
||||||
foreach ($_SESSION['update_results'] as $module => $updates) {
|
foreach ($_SESSION['update_results'] as $module => $updates) {
|
||||||
$output .= '<h3>' . $module . ' module</h3>';
|
$output .= '<h3>' . $module . ' module</h3>';
|
||||||
foreach ($updates as $number => $queries) {
|
foreach ($updates as $number => $queries) {
|
||||||
if ($number != '#abort') {
|
if ($number != '#abort') {
|
||||||
$output .= '<h4>Update #' . $number . '</h4>';
|
$messages = array();
|
||||||
$output .= '<ul>';
|
|
||||||
foreach ($queries as $query) {
|
foreach ($queries as $query) {
|
||||||
|
// If there is no message for this update, don't show anything.
|
||||||
|
if (empty($query['query'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($query['success']) {
|
if ($query['success']) {
|
||||||
$output .= '<li class="success">' . $query['query'] . '</li>';
|
$messages[] = '<li class="success">' . $query['query'] . '</li>';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$output .= '<li class="failure"><strong>Failed:</strong> ' . $query['query'] . '</li>';
|
$messages[] = '<li class="failure"><strong>Failed:</strong> ' . $query['query'] . '</li>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!count($queries)) {
|
|
||||||
$output .= '<li class="none">No queries</li>';
|
if ($messages) {
|
||||||
|
$output .= '<h4>Update #' . $number . "</h4>\n";
|
||||||
|
$output .= '<ul>' . implode("\n", $messages) . "</ul>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$output .= '</ul>';
|
$output .= '</ul>';
|
||||||
|
|
Loading…
Reference in New Issue