Problem/Motivation
In #3561087: Add equivalent updates hook to prevent downgrades from 10.6 to 11.2, discovered an issue with the equivalent updates that installing a site on the earlier version (e.g. 10.4) does not register the equivalent update for the later version (11.1), because equivalent updates are registered in update hooks, which do not run on site install.
So a user who installs a site on 10.4 will not see a warning messag when running database updates after going to 11.0.
This issue to address that gap by possibly registering equivalent updates in the system hook_install()implementation.
Steps to reproduce
Proposed resolution
Add a MarkFutureUpdateEquivalent attribute that can be applied to hook_update_N() functions. The attribute has two arguments, futureUpdateNumber and futureVersionString. During module install and when database updates are run, update functions are reflected to check for the attribute, and if the function has one, then the future equivalent version is registered.
Remaining tasks
User interface changes
Introduced terminology
API changes
See Proposed resolution.
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3561302
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:
- 3561302-register-equivalent-updates
changes, plain diff MR !14036
Comments
Comment #2
xjmComment #3
dwwComment #4
godotislateQuick thought is that we can do this with attributes.
For example, if we were doing this for 10.6/11.3:
10.6
11.3
Then when running database updates, check the update function for attributes. If it has the
MarkFutureUpdateEquivalentattribute, then register the equivalent update. If it has theCheckEquivalentUpdateattribute, then check for a registered equivalent update.During module install, in this part:
Can loop through the available update functions, use reflection to look for the
MarkFutureUpdateEquivalentattribute and register the equivalent update.Comment #5
catchI think #4 would work.
In slack @xjm brought up hard-coding (or semi-hardcoding, depending on how clever we can get with predicting future branch numbers) a list of equivalent branches, and then doing the registration directly in update.php and site install based on the current version. I'm not sure if we should explore that here or in a second issue.
Comment #7
godotislateSo #4 was actually pretty easy: MR 14036.
I didn't add the
#[CheckEquivalentUpdate]attribute, since I think the future version update doesn't need to run on module install. I don't think it's needed for no-op, either, because this already exists inupdate_do_one()(and the corresponding Drush command code):Drush will need to be updated to support the new attribute if we go this way.
Anyway, I wasn't sure if I could just add arguments to
UpdateHookRegistry::markFutureUpdateEquivalent(), so I followed the instructions per https://www.drupal.org/about/core/policies/core-change-policies/how-to-d.... I haven't created the follow up yet in case this isn't necessary.Comment #8
godotislateComment #9
godotislateComment #11
smustgrave commentedShould MarkFutureUpdateEquivalent get a CR?
Comment #12
nicxvan commentedI don't think so
Comment #13
godotislateAdded a CR for how to use the new attribute: https://www.drupal.org/node/3572245. Also updated the placeholder URL parameter change notice in the MR to the actual CR URL.
Comment #14
nicxvan commentedThank you for creating that, for some reason I misunderstood that the request was about the first equivalent update, not the actual api and attribute.
Makes sense to have a CR for this.
Comment #15
smustgrave commentedCR reads well to me, well detailed.
Comment #16
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #17
godotislateRe-ran PHPCS and PHPStan jobs only and they passed, so setting back to NR despite what the bot said.
Comment #18
smustgrave commentedRevisiting this one (sorry it fell off) but think it would be good to maybe land this in 11.4? With 12 approaching at the end of the year this may be useful for that. Going to mark it.
Comment #19
alexpottI think we need to do a bit more here.
We need to update module.api.php
I think we should deprecate calling markFutureUpdateEquivalent without a module and number and tell people to use the attribute.
And therefore we should make markFutureUpdateEquivalent @internal because there is no reason to call it. In fact it's wrong to not use the attribute.
Comment #20
godotislateUpdated MR per feedback.
Comment #21
godotislateComment #22
godotislateAddressed MR comments.
Comment #23
godotislateUpdate the CR.
Comment #24
nicxvan commentedLooks great now!
Read through the CR and the changes again.
Comment #26
quietone commentedI read the comments, the change record and the MR. I didn't do a code review.
I made significant changes to the change record and to comments in the MR. They will need to be reviewed, so changing status. For the change record it should be concise and limit to the change itself and what action sites may need to take. The level of detail to supply can be different for different types of changes, but in all cases, a good example can explain more than lots of text. And, I think it is fair to expect people who want to know more will follow the link to the issue or in some way read the code changes.
I updated credit.
Comment #27
godotislateThanks, @quietone. I took another pass at the CR and applied your MR suggestion. I also answered your question about the
@todo.Comment #28
godotislateCreated the follow up for Drupal 13 to make the parameters required: #3617733: [pp-1] Make $module and $ran_update_number parameters for UpdateHookRegistry::markFutureUpdateEquivalent required Drupal 13
Updated the MR to reference the follow up URL.
Comment #29
quietone commentedI tweaked comments. I also rebased. In Slack @godotislate confirmed by changes were OK, so I am restoring the RTBC on this issue.
Comment #30
alexpottCommitted and pushed 1ab223a55d3 to main and 941d0ac7d07 to 11.x. Thanks!