Run post update hook repeatedly using drush

By berliner, 9 February, 2023

Sometimes during development, you need to run the same post update hook repeatedly. Instead of resetting Drupals internal registry on already-run updates (see for example https://drupal.stackexchange.com/questions/238682/how-to-rerun-hook-pos…), we can also use drush to run a specific hook manually:

drush eval '\Drupal::moduleHandler()->loadInclude("MY_MODULE", "post_update.php"); $sandbox = []; NAME_OF_POST_UPDATE_HOOK($sandbox);'

Replace MY_MODULE with the name of you module and NAME_OF_POST_UPDATE_HOOK with the function name of your post update hook.Note the quotes. Depending on you shell, it might be important that the full command is using single quotes, otherwise the variable assignment can create a syntax error, see https://www.drupal.org/project/drush/issues/848086.

Version