3030
3131class Ps_Googleanalytics extends Module
3232{
33+ /**
34+ * @var string Name of the module running on PS 1.6.x. Used for data migration.
35+ */
36+ const PS_16_EQUIVALENT_MODULE = 'ganalytics ' ;
37+
3338 protected $ js_state = 0 ;
3439 protected $ eligible = 0 ;
3540 protected $ filterable = 1 ;
@@ -40,7 +45,7 @@ public function __construct()
4045 {
4146 $ this ->name = 'ps_googleanalytics ' ;
4247 $ this ->tab = 'analytics_stats ' ;
43- $ this ->version = '3.1.3 ' ;
48+ $ this ->version = '3.2.0 ' ;
4449 $ this ->ps_versions_compliancy = array ('min ' => '1.7.0.0 ' , 'max ' => _PS_VERSION_ );
4550 $ this ->author = 'PrestaShop ' ;
4651 $ this ->module_key = 'fd2aaefea84ac1bb512e6f1878d990b8 ' ;
@@ -59,6 +64,8 @@ public function install()
5964 Shop::setContext (Shop::CONTEXT_ALL );
6065 }
6166
67+ $ this ->uninstallPrestaShop16Module ();
68+
6269 if (parent ::install () &&
6370 $ this ->registerHook ('displayHeader ' ) &&
6471 $ this ->registerHook ('displayAdminOrder ' ) &&
@@ -86,6 +93,30 @@ public function uninstall()
8693 return false ;
8794 }
8895
96+ /**
97+ * Migrate data from 1.6 equivalent module (if applicable), then uninstall
98+ */
99+ public function uninstallPrestaShop16Module ()
100+ {
101+ if (!Module::isInstalled (self ::PS_16_EQUIVALENT_MODULE )) {
102+ return false ;
103+ }
104+ $ oldModule = Module::getInstanceByName (self ::PS_16_EQUIVALENT_MODULE );
105+ if ($ oldModule ) {
106+ if (method_exists ($ oldModule , 'uninstallTab ' )) {
107+ $ oldModule ->uninstallTab ();
108+ }
109+ // This closure calls the parent class to prevent data to be erased
110+ // It allows the new module to be configured without migration
111+ $ parentUninstallClosure = function () {
112+ return parent ::uninstall ();
113+ };
114+ $ parentUninstallClosure = $ parentUninstallClosure ->bindTo ($ oldModule , get_class ($ oldModule ));
115+ $ parentUninstallClosure ();
116+ }
117+ return true ;
118+ }
119+
89120 /**
90121 * Creates tables
91122 */
0 commit comments