diff --git a/README.md b/README.md index 9354f7fafef11547dcf5302fd73b94d6265bed6b..fd187a5675f1f44eae37f32ec3d62f5e92c3a08c 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,7 @@ None https://git.drupalcode.org/project/codit_batch_operations/-/blob/1.0.x/src/cbo_scripts/TestDo10Things.php ## How to run Batch Operation from hook_update_n()? -hook_update_n() runs before config import and before deploy (when using drush -deploy) Full documentation about hook_update_n() +hook_update_n() runs before config import before hook_post_update() and before deploy (when using drush deploy) They live in any module's install file. (MY_MODULE_NAME.install.php) Full documentation about hook_update_n() https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension%21module.api.php/function/hook_update_N/ 1. In whatever local/custom module you want to run this Batch Operation, add or use the existing MY_MODULE_NAME.install add the following @@ -77,6 +76,21 @@ https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension%21modul - drush deploy - visit /update.php and run updates in the UI. +## How to run Batch Operation from hook_post_update()? +Post update runs after all the hook_update_N have run. Post update hooks live in their own file (MY_MODULE_NAME.post_update.php). Hook_post_updates are not sequentially numbered, though they could be. They are suffixed with a name. I suggest using the same name as your BatchOp script or anything else that is meaningful. +1. In whatever local/custom module you want to run this Batch Operation, add + or use the existing MY_MODULE_NAME.post_update.php add the following + ```php + /** + * A description of what this post update will do. + */ + function MY_MODULE_NAME_post_update_SCRIPTNAME(&$sandbox) { + $script = \Drupal::classResolver('\Drupal\MY_MODULE_NAME\cbo_scripts\SCRIPTNAME'; + return $script->run($sandbox, 'post_update'); + } + ``` + hook_post_update functions are only ever run once. The function name is tracked, but is not sequential. Drupal is more stable and fully operationnal than it is during hook_update_N(). + ## FAQs - How do I run my script and have it keep going if there are errors?