1

I have a problem with the drush updb command which does not find the hook post updates of my custom module. I noticed that the module install saves the module's name string here in database, table "key_value", in BLOB file.

Table key_value : enter image description here BLOB file :

enter image description here

My post update in mymodule.post_update.php :

enter image description here

As it is present in the database, the command seems to consider that the hooks are executed when not. Is there a trick or something missing to solve this problem? My site is in 9.5.4.

New contributor
Orane B. is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

2 Answers 2

1

Sounds like you want to run update hooks on a newly installed module. Then you should use deploy hooks. Other then update and post-update hooks they run also for newly installed modules. The only requirement is you run drush deploy:hook during your deployment routine or simply switch from drush updb to drush deploy which also contains drush updb and drush deploy:hook already and runs everything in the right order.

(drush cim will enable the module and in the end drush deploy:hook will pick the deploy hooks up.)

Create a file MYMODULE.deploy.php and inside there put MYMODULE_deploy_NAME(&$sandbox) and go.

3
  • I tested your recommendations but I have this message: No pending deploy hook. I also tested via install profile and myprofile.post_update.php file but it can't find my function either...I'm out of ideas
    – Orane B.
    8 hours ago
  • @OraneB. – You enabled the module of course, right?
    – leymannx
    8 hours ago
  • - Yes, of course
    – Orane B.
    7 hours ago
0

Any update function listed in existing_updates has already been executed, and Drupal won't execute it again (post-update hooks typically operate on content, and you don't want to run those sorts of updates twice unintentionally).

If you're confident that executing the contents of that function is the right solution to your problem, then just change the function name to something that hasn't been executed before.

5
  • Thank you but that's not the solution because when the site is deployed in production, we won't be able to re-deliver each time to change each post update name... My question is why the first entry of the post update is stored in the database when installing the custom module when I haven't launched drush updb ?
    – Orane B.
    Mar 16 at 16:56
  • Because, by definition, your module should work without any updates being needed when it’s first installed. Update and post hooks are just to bring modules which are already installed in line with what a fresh installation of the same module would provide. It wouldn’t make sense for a module to be installed and immediately have an update available to run, so all of the updates are assumed to have run, and are logged as such
    – Clive
    Mar 16 at 17:00
  • Thanks, I think I understand. I have to explain the context then: in my module, I create a taxonomy via hook_install and I use a post_update to add the terms because I need the configuration to be imported to create the term only if the taxonomy exists. Since the hook is executed when the module is installed but the taxonomy has not yet been imported, then the term is not created...What would be the best solution?
    – Orane B.
    Mar 16 at 17:05
  • Ah ok - unless you want the vocab to be auto-removed when the module is uninstalled, there’s probably no point in providing a yml in config/install. Just create the vocab programmatically in hook_install before you create the terms
    – Clive
    Mar 16 at 17:20
  • Yes first, I had created the terms in the hook_install with the vocabulary. But the terms were not created. As if the vocabulary did not yet exist when the rest of the script was executed...
    – Orane B.
    8 hours ago

Your Answer

Orane B. is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.