Skip to content

Commit

Permalink
Merge pull request #1603 from drush-ops/post-update-hooks
Browse files Browse the repository at this point in the history
Support hook_post_update_X().
  • Loading branch information
jhedstrom committed Oct 6, 2015
2 parents 72f524e + 94a505f commit eab44eb
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions commands/core/drupal/update.inc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ function update_main() {
drupal_load_updates();
update_fix_compatibility();

// Pending hook_update_N() implementations.
$pending = update_get_update_list();

// Pending hook_post_update_X() implementations.
$post_updates = \Drupal::service('update.post_update_registry')->getPendingUpdateInformation();

$start = array();

$change_summary = [];
Expand All @@ -119,7 +123,7 @@ function update_main() {
}

// Print a list of pending updates for this module and get confirmation.
if (count($pending) || $change_summary) {
if (count($pending) || $change_summary || count($post_updates)) {
drush_print(dt('The following updates are pending:'));
drush_print();

Expand All @@ -130,16 +134,21 @@ function update_main() {
}
}

foreach ($pending as $module => $updates) {
if (isset($updates['start'])) {
drush_print($module . ' module : ');
foreach (array('update', 'post_update') as $update_type) {
$updates = $update_type == 'update' ? $pending : $post_updates;
foreach ($updates as $module => $updates) {
if (isset($updates['start'])) {
$start[$module] = $updates['start'];
foreach ($updates['pending'] as $update) {
drush_print(strip_tags($update), 2);
drush_print($module . ' module : ');
if (!empty($updates['pending'])) {
$start += [$module => array()];

$start[$module] = array_merge($start[$module], $updates['pending']);
foreach ($updates['pending'] as $update) {
drush_print(strip_tags($update), 2);
}
}
drush_print();
}
drush_print();
}
}

Expand Down Expand Up @@ -196,6 +205,15 @@ function drush_update_batch() {
}
}

// Apply post update hooks.
$post_updates = \Drupal::service('update.post_update_registry')->getPendingUpdateFunctions();
if ($post_updates) {
$operations[] = ['drush_drupal_cache_clear_all', []];
foreach ($post_updates as $function) {
$operations[] = ['update_invoke_post_update', [$function]];
}
}

// Lastly, perform entity definition updates, which will update storage
// schema if needed. If module update functions need to work with specific
// entity schema they should call the entity update service for the specific
Expand Down

0 comments on commit eab44eb

Please sign in to comment.