Problem/Motivation
We have an installation profile whose machine name is social and a module whose machine name is social_post. Because their machine names, some hook implementations, for example social_post_update_8100() or social_post_update_dependencies() are considered hook_post_update_NAME() implementations from the installation profile instead of hook_update_N() or hook_update_dependencies() implementations done from the module.
The same can happen with the Standard installation profile, for example.
Steps to reproduce
- Install Drupal using the Standard installation profile
- Install a module whose machine name is standard_post
- Go to update.php/selection and check the reported pending updates
I have also attached a test that confirms this for the testing install profile.
Proposed resolution
Accept as hook_post_update_NAME() implementations only the functions that are inside a MODULE.post_update.php/em> file, which is what the hook_post_update_NAME() documentation says those hooks should be placed.
Remaining tasks
Attach test module for those who want to test it using the above HTTAdd patch for testing purposes- Add patch with proposed fix
- See if we need to clean up the post_update storage
\Drupal::keyValue('post_update')->get('existing_updates') stores these hook_update_N() versions wrongly.
User interface changes
None.
API changes
None.
Data model changes
N/A.
Release notes snippet
N/A.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | after.png | 4.5 KB | rishi.kulshreshtha |
| #15 | before.png | 8.69 KB | rishi.kulshreshtha |
| Screenshot 2021-09-17 at 14.43.34.png | 148.78 KB | ronaldtebrake |
Issue fork drupal-3236316
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
avpadernoComment #3
ronaldtebrake commentedComment #4
ronaldtebrake commentedThere seems to be something wrong with the created branch of the issue fork, so for now just adding it as a patch.
I've added:
1. A new module called
testing_postwith some basic update hooks & post update hooks, but by using this module name it means that Drupal will treathook_update_Nandhook_update_dependenciesas post update hooks from the testing install profile instead.2.
UpdatePostUpdateInstallProfileTest.phpTo test if Drupal correctly sees these as update hooks and if the update hooks are being ran and not shown as pending post_update hooks after being fired.
Comment #6
ronaldtebrake commentedComment #7
larowlan@ronaldtebrake should I review the patch or the MR - I assumed the MR, so hiding the patch for now.
Left a comment on the MR, whilst I like the idea, I think there are modules (e.g. webform) for which this would be a hard break.
So we may need to be a bit more graceful, ie. trigger a deprecation error or something - not sure.
I think another approach is #3167625: Deprecate/replace hook_update_N() in favor of an object-oriented approach similar to Laravel migrations
Comment #8
joseph.olstadtests prove there's an issue
in addition we noticed another issue (this time D8 core though, but I imagine same issue in D9 , probably D7 also)
if the modulename is xyz_update
then in the xyz_update.install file, the hook updates don't get triggered
so the function looks like
this update hook isn't detected, doesn't run
Comment #10
damienmckennaComment #11
avpadernoComment #12
avpadernoComment #15
rishi.kulshreshthaThe patch got applied cleanly, but Drupal stopped detecting the unfinished
my_theme_post_update_custom_stuff(). I even made theNAMEcompletely numerical, for instance,my_theme_post_update_10001(), as a workaround, but it didn't work either.Comment #17
nicxvan commentedI think this is a duplicate https://www.drupal.org/project/drupal/issues/3129912