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

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 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,27 @@ 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, thus no data could be migrated.
// Initializing database structure & conf 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 +126,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