Message-ID: <929914494.377646.1711637354316.JavaMail.root@confluence-doc2-production> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_377645_13570071.1711637354311" ------=_Part_377645_13570071.1711637354311 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Since PrestaShop 1.5, it is possible to have your module auto-update: on= ce 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 mai= n things:
$this->version =3D '1.1';
/upgrade
sub-folder in the module's folder.For instance:
/* * File: /upgrade/Upgrade-1.1.php */ function upgrade_module_1_1($module) { // Process Module upgrade to 1.1 // .... return true; // Return true if success. }=20
...and then:
/* * File: /upgrade/Upgrade-1.2.php */ function upgrade_module_1_2($module) { // Process Module upgrade to 1.2 // .... return true; // Return true if succes. }=20
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 g=
amification module:
<?php if (!defined('_PS_VERSION_')) exit; function upgrade_module_1_4_9($object) { return Db::getInstance()->execute( 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'tab_advice` ( `id_tab` int(11) NOT NULL, `id_advice` int(11) NOT NULL, PRIMARY KEY (`id_tab`, `id_advice`) ) ENGINE=3D'._MYSQL_ENGINE_.' DEFAULT CHARSET=3Dutf8;'); }=20
The homeslider module's install-1.2.1.php
file does even mo=
re:
<?php if (!defined('_PS_VERSION_')) exit; function upgrade_module_1_2_1($object) { return Db::getInstance()->execute(' UPDATE '._DB_PREFIX_.'homeslider_slides_lang SET '.homeslider_stripslashes_field('title').', '.homeslider_stripslashes_field('description').', '.homeslider_stripslashes_field('legend').', '.homeslider_stripslashes_field('url') ); } function homeslider_stripslashes_field($field) { $quotes =3D array('"\\\'"', '"\'"'); $dquotes =3D array('\'\\\\"\'', '\'"\''); $backslashes =3D array('"\\\\\\\\"', '"\\\\"'); return '`'.bqSQL($field).'` =3D replace(replace(replace(`'.bqSQL($field= ).'`, '.$quotes[0].', '.$quotes[1].'), '.$dquotes[0].', '.$dquotes[1].'), '= .$backslashes[0].', '.$backslashes[1].')'; }=20
PrestaShop will then parse all of these scripts one after the other, seq= uentially. It is therefore highly advised to number your module's versions = sequentially, and to only use numbers =E2=80=93 because the upgrade code us= es PHP's version_compare() method.
If the new version of your module adds or update its hooks, you should m= ake sure to update them too
Indeed, since the hooks are (usually) defined when the module is install= ed, PrestaShop will not install the module again in order to include the ne= w hooks' code, so you have to use the upgrade methods:
For instance, here's the install-1.2.php
file from the bloc=
kbestseller module:
<?php if (!defined('_PS_VERSION_')) exit; function upgrade_module_1_2($object) { return ($object->registerHook('addproduct')=20 && $object->registerHook('updateproduct')=20 && $object->registerHook('deleteproduct')=20 && $object->registerHook('actionOrderStatusPostUpdate')); }=20