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.

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.

  • 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? – Joseph Hovik Apr 26 '17 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 Apr 26 '17 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 Apr 26 '17 at 21:39

Your Answer

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.