Skip to content

Instantly share code, notes, and snippets.

@bryanbraun
Created June 19, 2017 20:24
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanbraun/852646078ef6b33d2dc2ecacc96c9865 to your computer and use it in GitHub Desktop.
Save bryanbraun/852646078ef6b33d2dc2ecacc96c9865 to your computer and use it in GitHub Desktop.
A drush script for reseting post_update hooks. For more details, see https://drupal.stackexchange.com/q/238682/11788
#!../vendor/bin/drush
// <?php
// ^^^ For syntax highlighters only
//
// This is a drush shell script, designed to help debug and reset post_update
// hooks. For details, see: http://www.drush.org/en/master/shellscripts/
$key_value = \Drupal::keyValue('post_update');
$update_list = $key_value->get('existing_updates');
$most_recent_update = end($update_list);
drush_print("The most recent post_update hook is $most_recent_update");
$choice_1 = drush_confirm('Do you want to reset this hook?');
if ($choice_1) {
$removed_el = array_pop($update_list);
$key_value->set('existing_updates', $update_list);
drush_print("$removed_el was reset");
} else {
$choice_2 = drush_choice($update_list, dt('Which post_update hook do you want to reset?'));
if ($choice_2) {
$removed_el = $update_list[$choice_2];
unset($update_list[$choice_2]);
$key_value->set('existing_updates', $update_list);
drush_print("$removed_el was reset");
} else {
drush_print("Reset was cancelled");
}
}
@wayne-weibel
Copy link

wayne-weibel commented Feb 17, 2022

This works well, I had to update the functions for Drush 10x. AND a gotcha is that when selecting '1' in the prompt it will return 0 which evaluates to false, so you need to use $choice !== FALSE. Also, with the new choice function the Cancel message is automatically handled

updated for Drupal 9.x Drush 10.x https://gist.github.com/wayne-weibel/01e7f00b32dbcb96eb2785817693483f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment