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

leymannx created an issue. See original summary.

norman.lol’s picture

frob’s picture

Would this not make Drush a hard dependency of Drupal?

norman.lol’s picture

This 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.

frob’s picture

Maybe 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.

moshe weitzman’s picture

@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.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

frob’s picture

@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.

bircher’s picture

RE #8: Yes this issue is just as much about adding the hook_deploy_NAME to 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.

frob’s picture

Issue summary: View changes

I updated the IS to show that this is about taking that hook_deploy_NAME hook from drush and adding it to core --not just add a deploy.php file that runs implemented hook_deploy_NAME hooks.

bircher’s picture

Issue summary: View changes

Deploy 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.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

leo pitt’s picture

I 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?

bircher’s picture

RE #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?

moshe weitzman’s picture

This 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.

duaelfr’s picture

Title: Add new route to run deploy hook implementations from the UI » Define new hook_deploy_NAME hook and add new route to run their implementations from the UI
Issue summary: View changes

Minor changes for clarity

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.