Skip to content

Commit

Permalink
Merge pull request #24 from Quetzacoalt91/ps1.6-module-migration
Browse files Browse the repository at this point in the history
Uninstall module used on PS 1.6 before using this one
  • Loading branch information
atomiix authored Jul 2, 2021
2 parents fc78f0b + dc5c939 commit 4237f4c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ps_mainmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

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

const MENU_JSON_CACHE_KEY = 'MOD_BLOCKTOPMENU_MENU_JSON';

protected $_menu = '';
Expand Down Expand Up @@ -98,6 +103,10 @@ public function install($delete_params = true)
}

if ($delete_params) {
if ($this->uninstallPrestaShop16Module()) {
Configuration::deleteByName('MOD_BLOCKTOPMENU_SEARCH');
return true;
}
if (!$this->installDb() || !Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_ITEMS', 'CAT3,CAT6,CAT9')) {
return false;
}
Expand Down Expand Up @@ -163,6 +172,27 @@ public function reset()
return true;
}

/**
* 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()
{
$id_lang = (int) Context::getContext()->language->id;
Expand Down

0 comments on commit 4237f4c

Please sign in to comment.