Skip to content

Commit d458506

Browse files
Merge pull request #34 from Quetzacoalt91/ps1.6-module-migration
Uninstall module used on PS 1.6 before using this one
2 parents ea820dd + b8faa0b commit d458506

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

ps_googleanalytics.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030

3131
class 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;
@@ -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

Comments
 (0)