Search code examples
drupaldrupal-7drupal-modules

How can I check if database update is required before update module


Is there any good way for it? Like check some specific code in module.


Solution

  • Yes, it's possible.

    Let's have an example with webform module.

    Inside of each module there is an install file. Open it and scroll to the down, find the last hook. In our example it's:

    webform_update_7430

    Here is a screen (bottom part) of install file.

    enter image description here

    How to check if it is going to run or already processed?

    In order to do that, you need to check system table in your drupal database. Find the webform module in system table and check value in schema version column. That will be the number of last hook which was run for this module, if in your install file hooks have higher number it means they will be executed during update.

    enter image description here