Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninstall module used on PS 1.6 before using this one #20

Merged
merged 1 commit into from Jul 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion ps_emailalerts.php
Expand Up @@ -32,6 +32,11 @@

class Ps_EmailAlerts extends Module
{
/**
* @var string Name of the module running on PS 1.6.x. Used for data migration.
*/
const PS_16_EQUIVALENT_MODULE = 'mailalerts';

protected $html = '';

protected $merchant_mails;
Expand Down Expand Up @@ -105,7 +110,7 @@ public function install($delete_params = true)
return false;
}

if ($delete_params) {
if ($delete_params && $this->uninstallPrestaShop16Module()) {
Configuration::updateValue('MA_MERCHANT_ORDER', 1);
Configuration::updateValue('MA_MERCHANT_OOS', 1);
Configuration::updateValue('MA_CUSTOMER_QTY', 1);
Expand Down Expand Up @@ -156,6 +161,27 @@ public function uninstall($delete_params = true)
return parent::uninstall();
}

/**
* Migrate data from 1.6 equivalent module (if applicable), then uninstall
*/
public function uninstallPrestaShop16Module()
{
if (!Module::isInstalled(self::PS_16_EQUIVALENT_MODULE)) {
return false;
}
$oldModule = Module::getInstanceByName(self::PS_16_EQUIVALENT_MODULE);
if ($oldModule) {
// This closure calls the parent class to prevent data to be erased
// It allows the new module to be configured without migration
$parentUninstallClosure = function() {
return parent::uninstall();
};
$parentUninstallClosure = $parentUninstallClosure->bindTo($oldModule, get_class($oldModule));
$parentUninstallClosure();
}
return true;
}

public function reset()
{
if (!$this->uninstall(false)) {
Expand Down