Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
Uninstall module used on PS 1.6 before using this one
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Jun 14, 2019
1 parent debae6b commit 1c46630
Showing 1 changed file with 43 additions and 14 deletions.
57 changes: 43 additions & 14 deletions ps_reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

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

private $conf_keys = array();

public function __construct()
Expand Down Expand Up @@ -85,23 +90,26 @@ public function __construct()

public function install()
{
Db::getInstance()->execute('
CREATE TABLE '._DB_PREFIX_.'log_email (
`id_log_email` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`id_email_type` INT UNSIGNED NOT NULL ,
`id_cart_rule` INT UNSIGNED NOT NULL ,
`id_customer` INT UNSIGNED NULL ,
`id_cart` INT UNSIGNED NULL ,
`date_add` DATETIME NOT NULL,
INDEX `date_add`(`date_add`),
INDEX `id_cart`(`id_cart`)
) ENGINE='._MYSQL_ENGINE_);
if (!$this->uninstallPrestaShop16Module()) {
// 1.6 module was not installed, initializing data
Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.'log_email (
`id_log_email` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`id_email_type` INT UNSIGNED NOT NULL ,
`id_cart_rule` INT UNSIGNED NOT NULL ,
`id_customer` INT UNSIGNED NULL ,
`id_cart` INT UNSIGNED NULL ,
`date_add` DATETIME NOT NULL,
INDEX `date_add`(`date_add`),
INDEX `id_cart`(`id_cart`)
) ENGINE='._MYSQL_ENGINE_
);

foreach ($this->conf_keys as $key) {
Configuration::updateValue($key, 0);
foreach ($this->conf_keys as $key) {
Configuration::updateValue($key, 0);
}
}


return parent::install();
}

Expand All @@ -117,6 +125,27 @@ public function uninstall()
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 getContent()
{
$html = '';
Expand Down

0 comments on commit 1c46630

Please sign in to comment.