1

Say I'm trying to update a module from version 7.03 to 7.04, and version 7.04 has a function called mymodule_update_7704() which updates the module's schema.

If I go to the modules page and update mymodule, will the mymodule_update_7704() function run, and update the module's schema?

Also, if the above is correct and mymodule_update_7704() does run, will the user have to click to run the update, or is it silent?

Sorry if this question seems elementary, I just can't test this without releasing my module, and I'd rather know first before I do release.

1 Answer 1

0

hook_update_N is only invoked when:

  • The update process is running (via /update.php, drush, etc).
  • The current schema version for the module is less than the update hook's schema version (The N in hook_update_N).

No updates are run when you visit the modules admin page, the process will always be invoked by an administrator (or perhaps an automated task, but never silently/automatically by Drupal itself).

As an aside (in case it comes to bite you at some point), no update hooks are invoked when installing a module, only for already-installed modules during the update process. The update hooks are only for getting older installations up to speed with what the current release offers upon installation anyway.

As another aside, your schema numbering looks a bit suspect if you want to stay within common practice; have a read through the hook_update_N docs for more info, but your numbering should probably be in the 7100s at this point.

3
  • Thanks Clive. I guess I was looking to update the schema without any interaction from the user. Is that possible, or will they still have to click to apply the update? Commented Apr 26, 2017 at 21:34
  • Drupal only gives you the one "safe" option, really, it doesn't differentiate between major/minor updates, it just has...updates, and they run through the one process. It's the process most people will be familiar with to be honest, and one that core already contains notification functionality for, so it's probably best to bite the bullet and just require the update. Some might argue that any schema change is potentially BC-breaking anyway, and maybe should be considered major ;)
    – Clive
    Commented Apr 26, 2017 at 21:38
  • Oh your comment changed a bit...you certainly could do it without user interaction; stick some DB calls in hook_init based on a boolean variable or similar...but I wouldn't recommend it, people might get mad
    – Clive
    Commented Apr 26, 2017 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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