Problem/Motivation
In #474684: Allow themes to declare dependencies on modules we enabled themes to have module dependencies but we provided no way for an existing theme to add a module as a dependency without breaking.
Steps to reproduce
Add a dependency to a theme that is already installed on a site. It will break if the theme relies on code from the module and the module is not installed.
Proposed resolution
Gives themes the ability to have post update hooks. This would mean that they can install modules and also fix their config if they've changed their theme setting config structure.
Remaining tasks
Fix drush: https://github.com/drush-ops/drush/pull/5120
Harden tests per #16?
User interface changes
API changes
- Themes can implement
HOOK_post_update_NAME()andHOOK_removed_post_updates() \Drupal\Core\Update\UpdateRegistry::getModuleUpdateFunctions()is deprecated in favour of\Drupal\Core\Update\UpdateRegistry::getUpdateFunctions()\Drupal\Core\Update\UpdateRegistry::filterOutInvokedUpdatesByModule()is deprecated in favour of\Drupal\Core\Update\UpdateRegistry::filterOutInvokedUpdatesByExtension()
Data model changes
Release notes snippet
Issue fork drupal-3259188
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
cilefen commentedComment #3
bbralaComment #5
alexpottComment #6
lauriiiComment #7
alexpottComment #8
alexpottComment #9
mherchelThis is a blocker for #3257274: Implement color changing theme settings for Olivero
Comment #10
bbralaComment #11
chr.fritschThis looks pretty good. I tested it in the gin theme and all my updates ran. Since this is needed by Olivero and would also be lovely for gin, I would like to this going.
One sidenote: I first tried to run the update with drush, but that didn't work. It discovered the new update hook, but was not able to run it. After that I used update.php and everything worked well. So I think we have to open a follow-up in the drush issue queue.
Comment #13
dwwLeaving at RTBC, but would love clarification on the deprecation strategy.
Thanks!
-Derek
Comment #14
dwwp.s. I was going to ask what's up with the 2 seemingly duplicate CRs, but the commits on the MR say:
More closely reading the actual CRs and it's clear why they're different. Posting here in case anyone else was confused by this like I was. 😅
Comment #15
catchMR looks ready. The one remaining issue is we currently don't currently have any answer to hook_removed_post_updates() endlessly growing, and once we do, we'll need to apply that to themes too, and one of the possible ways we came up with for that was a hook_update_N(), and nooooo. But... we will just need to find a way that does not involve hook_update_N(), there are other problems with that anyway. Can't find the issue that discusses this, but original is here: #3066801: Add hook_removed_post_updates().
Looks like we still need to open an issue against drush to add support per #3259188-11: Extend post update system to provide themes a way to install newly-required dependencies.
Comment #16
alexpottWhile working on the Drush fix I noticed that we needed some more changes in update.inc. Specifically...
This code is copied in Drush. Nothing was broken in core because the theme post update function was already loaded. By changing
\Drupal::moduleHandler()->loadInclude($module, 'php', $module . '.post_update');to\Drupal::service('update.post_update_registry')->getUpdateFunctions($extension);ensure the post update function file is loaded. Tests were not failing because the batch is immediately processed in the same request that has create the batch by listing all the available update functions.Comment #17
dww@alexpott re: #16: Thanks for catching that! It's unfortunate that you squashed all the commits in the MR branch as part of your rebase, since now it's a little harder to review what you actually changed. Thankfully, Gitlab remembers it as commit 78c7ca08, and that all looks great.
It sounds like you're already working on the drush issue. Would you be willing to add the link here so we can remove the "Needs follow-up" tag?
I almost moved this back to RTBC, but I'm also wondering if we want to try to harden the tests any more, per the end of your comment.
I'm also not sure if I should attempt that myself, or retain my reviewer status in here. 😉 Please advise.
Thanks!
-Derek
Comment #18
dwwFound https://github.com/drush-ops/drush/pull/5120 and added to the summary.
At this point, I think RTBC is safe. The committer can decide to push-back for more thorough tests if they deem it necessary and worth holding up this blocker for.
Thanks again!
-Derek
Comment #19
alexpottI think it is quite hard to test this because we'd need an update that has a sleep in it to force batching.
Re the squash - sorry but for whatever reason the MR would no longer merge 10.x cleanly at all. There were conflicts in pieces of code completely untouched by the change so I just obliterated everything and started again. Hence pasting what I changed. Thanks for posting the link to the Drush work.
Comment #20
dwwSounds great, thanks. Then RTBC it is! 🎉
Comment #23
catchCommitted/pushed to 10.0.x and cherry-picked to 9.4.x, thanks!
It'd be good to have the more expansive test coverage however:
1. Agreed it seems hard and potentially unreliably to trigger the batch
2. The easiest way to trigger the batch will be to have a real post update and real updates giving us implicit test coverage - we'll probably get that with Olivero + a few core updates over the next months.
Comment #25
heddnCross posting here that #3294299: Regression in functional test performance with a large number of modules was opened as a regression from this issue.