Skip to end of metadata
Go to start of metadata

Auto-updating modules

Since PrestaShop 1.5, it is possible to have your module auto-update: once a new version is available on Addons, PrestaShop suggests an "Update it!" button to the user. Clicking this button will trigger a series of methods, each leading closer to the latest version of your module.

In order to bring auto-update support to your module, you need three main things:

  • Clearly indicate the module's version number in its constructor method: $this->version = '1.1';
  • Create an /upgrade sub-folder in the module's folder.
  • Add an auto-update PHP script for each new version.

For instance:

...and then:

Each method should bring the necessary changes to the module's files and database data in order to reach the latest version.

For instance, here is the install-1.4.9.php file from the gamification module:

The homeslider module's install-1.2.1.php file does even more:

PrestaShop will then parse all of these scripts one after the other, sequentially. It is therefore highly advised to number your module's versions sequentially, and to only use numbers – because the upgrade code uses PHP's version_compare() method.

If the new version of your module adds or update its hooks, you should make sure to update them too

Indeed, since the hooks are (usually) defined when the module is installed, PrestaShop will not install the module again in order to include the new hooks' code, so you have to use the upgrade methods:

For instance, here's the install-1.2.php file from the blockbestseller module:

  • No labels