hi everone...
i would like to undestand one thing about that hook: if a module has

mymodule_install()

mymodule_update_6100()
mymodule_update_6101()
mymodule_update_6102()
...
mymodule_update_6120()

if i put that module in a new drupal installation, hook_update_N will be activated or only hook_install will be done?
thank you very much

Comments

aaronbauman’s picture

all your hook_update_N functions will fire when you install the module.

the system table keeps track of the update status of all modules.
when you install a newer version of the module, only the newest hook_update_N functions will fire.
e.g:
version 1.1 has functions hook_update_1 and hook_update_2
version 1.2 has functions hook_update_1, hook_update_2, and hook_update_3

when you install version 1.1, hook_update_1 and _2 will fire.
when you update (NOT uninstall/reinstall) to version 1.2, only hook_update_3 will fire.

jweowu’s picture

all your hook_update_N functions will fire when you install the module.

This is incorrect.

When you first install a new module, none of the hook_update_N functions are executed.

Your basic installation functions (hook_install, hook_schema) must therefore always be up-to-date.

When the module is first installed, it looks for hook_update_N functions, and stores the value of the most recent one (or the SCHEMA_INSTALLED constant, if no updates exist) as the 'schema_version' for this module in the system table. See _drupal_install_module() in install.inc (Drupal 6).

Subsequent updates will then execute in sequence the hook_update_Ns that are more recent than the known 'schema_version'.