Skip to content
Snippets Groups Projects
Commit fc8f09b3 authored by Steve Wirt's avatar Steve Wirt
Browse files

Issue #3431994 by swirt: Document how to run from a hook_post_update

parent f618e246
No related branches found
No related tags found
No related merge requests found
......@@ -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?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment