Created
June 19, 2017 20:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!../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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 handledupdated for Drupal 9.x Drush 10.x https://gist.github.com/wayne-weibel/01e7f00b32dbcb96eb2785817693483f