Problem/Motivation
Drush 10.3.0 added a new deploy command to standardize the order of Drush commands during Drupal deployments. drush deploy also runs the `deploy:hook` subcommand in its end to have hook_deploy_NAME(&$sandbox) implementations from MODULE_NAME.deploy.php files picked up after configuration import has run. This allows us to trigger programmatic content updates after the relying configuration has been imported.
Classic example: You add a new field with a default value to an existing entity type; to have this default value set for all existing entities you need to set it programmatically. And you want to do this all in one release. hook_update_N is too early as the configuration which adds this new field hasn't been imported yet (same for hook_post_update_NAME). Instead, implement the content updates in hook_deploy_NAME and it will be triggered after the new field with the default value has been created and registered in the database.
This issue is about bringing that hook into core and adding a route /admin/deploy to run those post deployment hooks.
Steps to reproduce
Implement a hook_deploy_NAME and try to run it from /admin/deploy
Proposed resolution
Add a new route to allow deploy hooks to be run from the UI, for example /admin/deploy.
Remaining tasks
Add documentation for hook_deploy_NAME from drush to core.
Decide on what to name the new route.
Add menu items
Implement batch
Add tests
Release notes
User interface changes
New page, similar to the config import, with a list of pending deploy hooks and a "run" button which runs them in a batch.
Maybe a link on the config import page when there is nothing to import but pending deploy hooks.
API changes
Adding possibility to run hook_deploy_NAME from the UI.
Data model changes
none
Release notes snippet
tbd
Comments
Comment #2
norman.lolComment #3
frobWould this not make Drush a hard dependency of Drupal?
Comment #4
norman.lolThis has nothing to do with Drush. It's just about Drupal being able to recognize and run the deploy hooks. This is probably what you asked for in the other issue: That it's nice that Drush can do this, but what about Drupal? And I think you are right. We can run update hooks and config import from the UI, so we should also be able to run deploy hooks from the UI.
Comment #5
frobMaybe I am confused. I just searched api.drupal.org and didn't find any
hook_deploy_NAME(&$sandbox)isn't this hook something that drush does? Meaning, without drush not only can we not run this hook but core has no deploy hook implementation at all. Which would mean that this issue is about putting a front end in core for a drush only api. I could be wrong though.Comment #6
moshe weitzman commented@frob - this issue wants to create a new hook in drupal and provide a UI run it. The new hook would be documented in an api file in drupal core and it would then be like
hook_update_n()- a hook invented by drupal that you can optionally run via Drush.Drupal core wont have any implementations of the hook because this hook is meant to be used by sites and not by core and contrib.
Comment #8
frob@moshe #2901418: Add hook_post_config_import_NAME after config import was about adding that hook to core --and that keeps getting marked as duplicate. This issue is only about being able to invoke the deploy hook from drush with a /deploy.php route in core. At least that is how I read it. I am not saying I couldn't be wrong. But the only way to run a deploy hook is from drush and the only docs I can find on deploy hooks are in drush docs.
Comment #9
bircherRE #8: Yes this issue is just as much about adding the
hook_deploy_NAMEto core as the other issue was about adding the other hook to core.It is absolutely equivalent. The only difference is how the hook is called and when the hook is invoked.
In the other issue we wanted to invoke them at the end of a config import (bad idea, speaking from experience).
In this issue we want to make a dedicated UI which displays all pending hooks and invokes them in a batch process. (much better idea base on experience with drush)
There is nothing here that would make drupal depend on drush more than it already does (ie only for users who need drush to work with drupal, not in a technical sense). Drush is the command line user interface to run the update hooks. And drush is the command line user interface to run deploy hooks. It just so happens that drush supports the deploy hook already now whereas drupal doesn't yet because this issue here is not fixed yet. So the fact that the documentation exists only in drush is just a consequence of it not having been added to drupal core in this issue.
Comment #10
frobI updated the IS to show that this is about taking that
hook_deploy_NAMEhook from drush and adding it to core --not just add a deploy.php file that runs implementedhook_deploy_NAMEhooks.Comment #11
bircherDeploy hooks do not need to be run from their own front controller (ie /core/deploy.php) but instead they can be run from a normal route like the config import.
Also I don't think we will need anything special, just a table with the pending hooks and a button to run them all.
Comment #16
leo pitt commentedI find this confusing. So is
hook_deploy_NAME()going to be added to Drupal core (as opposed to drush only)? And if so, does anyone know the issue where this is being addressed?Comment #17
bircherRE #16: This here is that issue :D
I think one of the reasons this has not gained any traction is that almost everyone uses drush anyway and Drupal core or contrib should not actually have any deploy hooks. Deploy hooks are meant for modules that are unique to a specific site as the point is to being able to rely on a particular configuration which is exported and committed along with the hook implementation.
But if you wish to have a UI for it in core then this is the issue. Alternatively it would also be relatively easy to create a contrib module for it.
Ultimately this is something that has to be decided by ... the framework managers, I guess?
Comment #18
moshe weitzman commentedThis issue. It will be added when someone is motivated to make an MR and shepherd it through to completion. So far nobody has turned up to do that.
Comment #19
duaelfrMinor changes for clarity