Skip to content
Snippets Groups Projects
Commit d151ea91 authored by Angie Byron's avatar Angie Byron
Browse files

#554754 by gordon and dww: Added a new function update_get_update_list() to...

#554754 by gordon and dww: Added a new function update_get_update_list() to return list of pending updates.
parent 0e116ff9
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -417,3 +417,63 @@ function update_finished($success, $results, $operations) {
}
}
/**
* Return a list of all the pending database updates.
*
* @return
* An associative array keyed by module name which contains all information
* about database updates that need to be run, and any updates that are not
* going to proceed due to missing requirements. The system module will
* always be listed first.
*
* The subarray for each module can contain the following keys:
* - start: The starting update that is to be processed. If this does not
* exist then do not process any updates for this module as there are
* other requirements that need to be resolved.
* - warning: Any warnings about why this module can not be updated.
* - pending: An array of all the pending updates for the module including
* the update number and the description from source code comment for
* each update function. This array is keyed by the update number.
*/
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();
$updates = drupal_get_schema_versions($module);
// Skip incompatible module updates, otherwise test schema versions.
if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) {
// module_invoke returns NULL for nonexisting hooks, so if no updates
// are removed, it will == 0.
$last_removed = module_invoke($module, 'update_last_removed');
if ($schema_version < $last_removed) {
$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) {
// The description for an update comes from its Doxygen.
$func = new ReflectionFunction($module . '_update_' . $update);
$description = str_replace(array("\n", '*', '/'), '', $func->getDocComment());
$ret[$module]['pending'][$update] = "$update - $description";
if (!isset($ret[$module]['start'])) {
$ret[$module]['start'] = $update;
}
}
}
if (!isset($ret[$module]['start']) && isset($ret[$module]['pending'])) {
$ret[$module]['start'] = $schema_version;
}
}
}
if (empty($ret['system'])) {
unset($ret['system']);
}
return $ret;
}
......@@ -48,51 +48,29 @@ function update_script_selection_form() {
// Ensure system.module's updates appear first
$form['start']['system'] = array();
$modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
foreach ($modules as $module => $schema_version) {
$pending = array();
$updates = drupal_get_schema_versions($module);
// Skip incompatible module updates completely, otherwise test schema versions.
if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) {
// module_invoke returns NULL for nonexisting hooks, so if no updates
// are removed, it will == 0.
$last_removed = module_invoke($module, 'update_last_removed');
if ($schema_version < $last_removed) {
$form['start'][$module] = array(
'#title' => $module,
'#item' => '<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.',
'#prefix' => '<div class="warning">',
'#suffix' => '</div>',
);
continue;
}
$updates = drupal_map_assoc($updates);
foreach (array_keys($updates) as $update) {
if ($update > $schema_version) {
// The description for an update comes from its Doxygen.
$func = new ReflectionFunction($module . '_update_' . $update);
$description = str_replace(array("\n", '*', '/'), '', $func->getDocComment());
$pending[] = "$update - $description";
if (!isset($default)) {
$default = $update;
}
}
}
if (!empty($pending)) {
if (!isset($default)) {
$default = $schema_version;
}
$form['start'][$module] = array(
'#type' => 'hidden',
'#value' => $default,
);
$form['start'][$module . '_updates'] = array(
'#markup' => theme('item_list', $pending, $module . ' module'),
);
}
$updates = update_get_update_list();
foreach ($updates as $module => $update) {
if (!isset($update['start'])) {
$form['start'][$module] = array(
'#title' => $module,
'#item' => $update['warning'],
'#prefix' => '<div class="warning">',
'#suffix' => '</div>',
);
continue;
}
if (!empty($update['pending'])) {
$form['start'][$module] = array(
'#type' => 'hidden',
'#value' => $update['start'],
);
$form['start'][$module . '_updates'] = array(
'#markup' => theme('item_list', $update['pending'], $module . ' module'),
);
}
if (isset($update['pending'])) {
$count = $count + count($update['pending']);
}
unset($default);
$count = $count + count($pending);
}
if (empty($count)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment