Problem/Motivation
Currently all the post_update methods are run on alphabetical order (see UpdateRegistry::getAvailableUpdateFunctions).
The documentation suggests adding numerical prefix the update names or making them completely numerical in order to control the order of execution. However, this does not take into account that post_update methods can come from different components which makes controlling the order harder.
In contrast, update methods can define requirements to one another which ensures that the order in which they run is consistent.
Proposed resolution
We could either implement a more complex requirement based solution for post_updates (like we do with updates) or we could add an alter hook that allows to alter the final order of execution.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | 3129231-26.patch | 6.01 KB | joevagyok |
| #22 | 3129231-nr-bot.txt | 138 bytes | needs-review-queue-bot |
| #20 | 15-20.diff | 660 bytes | sinn |
| #20 | drupal-post_update_alter-3129231-20.patch | 6.02 KB | sinn |
| #11 | 3129231-11.patch | 5.9 KB | chewie |
Issue fork drupal-3129231
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
ieguskiza commentedI gave a go to a simple alter hook and included a small test that shows what it would allow to do.
Comment #3
upchuk commentedThis comment is outdated. There are no enabled/disabled modules anymore.
Also, the function below doesn't do that. It loops through the extension list and it simply skips the uninstalled ones.
It doesn't return anything.
See where? We should add documentation to the hook in the module.api.php file next to the others.
Missing protected.
I would rephrase this comment to something a bit more relevant to what the code does below, if needed at all. Not to mention that you are loading all extensions, not just modules :)
Can we get a patch that contains the failing test that proves this actually works (the fact that the post update function goes to the end from another location)?
Please be aware that the tests are also failing.
Comment #4
ieguskiza commented1. I removed the extra comment, as you mention it doesn't add anything of value.
2. The method does return a list of callable strings, I kept the documentation.
3. Good point, I added the entry on module.api.php.
4. Good point, fixed.
5. I removed most of the comment. However reading through drupal_get_installed_schema_version it does appear to only return module information, so it would still be correct.
6. I added an extra patch with only the tests.
Comment #5
ieguskiza commentedUnit tests failed because we use a global function in the updateregistry class. I am not sure if we even need to include the install files since we can rely on the post_update files entirely so I removed that part for now.
Comment #7
ieguskiza commentedRerolling patch for 8.9
Comment #8
upchuk commentedLooks good to me. We have been using this for quite some time now.
Comment #9
quietone commentedThank you for getting this to RTBC.
Doing a 'light' review to make sure this ready for a committer. I found a few things that should be addressed so setting NW.
Comment #10
ravi.shankar commentedFixed CS issues of patch #7.
Comment #11
chewie commentedRerolled patch for 9.1.x
Comment #12
upchuk commentedRerolled the patch for 9.2.x
Comment #13
upchuk commentedFixing phpcs issue.
Comment #15
upchuk commentedFixed the test.
Comment #18
longwaveIn #3262036: Convert hook_update_dependencies() to PHP attributes I propose using PHP attributes instead of a separate hook to determine hook_update_N() dependencies.
Perhaps we could do the same here, although this would mean this was PHP 8 and 10.0.x only.
Comment #20
sinn commentedRerolled patch for 9.4.x
Comment #22
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #26
joevagyok commentedRerolled over 11.x.
Comment #27
joevagyok commentedPatch for 10.5.x version of core.
Comment #28
nicxvan commentedI'll be honest, I have strong reservations about this.
We do have a way to order them already just by numbering them.
This looks suspiciously like hook module implements alter that was a monumental effort to replace.
Can we get a description of the scenarios where ordering is necessary here and why alpha numeric isn't sufficient?
I'd also want to review hook update dependencies in depth to see if that can be applied.
Comment #29
joevagyok commentedIn the patch made for 10.5.x in comment #27 I realized that one function call is missing and the feature doesn't work as expected. Uploading the correct patch.
Comment #30
joevagyok commentedComment #31
joevagyok commented@nicxvan Our use case that requires this is the following:
We have an install profile and we need to make sure, that all dependent components/modules run their post_update functions before the install profile post updates, hence why the existing solutions are not enough, like it is described in the issue description.
Comment #32
joevagyok commentedFixed the patch for 10.5.x.
Comment #33
joevagyok commentedAdded the missing part in the 10.5.x patch.
Comment #34
hernani commentedPatch for 11.2.x
Comment #35
quietone commentedHi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Thanks.
Comment #36
quietone commented