From b3e8525c8e69576391656199028555a01d527a4f Mon Sep 17 00:00:00 2001 From: max-baranikov Date: Mon, 12 Sep 2022 21:22:53 +0300 Subject: [PATCH] Do not remove tabs when deactivating module in Multistore --- .../admin/RetailcrmModuleDisablingAware.php | 41 +++++++++++++++++++ .../admin/RetailcrmSettingsLinkController.php | 2 +- retailcrm/retailcrm.php | 19 ++++++--- 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 retailcrm/controllers/admin/RetailcrmModuleDisablingAware.php diff --git a/retailcrm/controllers/admin/RetailcrmModuleDisablingAware.php b/retailcrm/controllers/admin/RetailcrmModuleDisablingAware.php new file mode 100644 index 0000000..9ee496c --- /dev/null +++ b/retailcrm/controllers/admin/RetailcrmModuleDisablingAware.php @@ -0,0 +1,41 @@ + + * @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL + * @license https://opensource.org/licenses/MIT The MIT License + * + * Don't forget to prefix your containers with your own identifier + * to avoid any conflicts with others containers. + */ + +interface RetailcrmModuleDisablingAware +{ +} diff --git a/retailcrm/controllers/admin/RetailcrmSettingsLinkController.php b/retailcrm/controllers/admin/RetailcrmSettingsLinkController.php index 3429373..10d719f 100644 --- a/retailcrm/controllers/admin/RetailcrmSettingsLinkController.php +++ b/retailcrm/controllers/admin/RetailcrmSettingsLinkController.php @@ -38,7 +38,7 @@ require_once dirname(__FILE__) . '/../../bootstrap.php'; -class RetailcrmSettingsLinkController extends RetailcrmAdminAbstractController +class RetailcrmSettingsLinkController extends RetailcrmAdminAbstractController implements RetailcrmModuleDisablingAware { public static function getParentId() { diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index c118734..f66bd69 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -240,12 +240,12 @@ class RetailCRM extends Module * @throws PrestaShopDatabaseException * @throws PrestaShopException */ - public function uninstallTab() + public function uninstallTab($forceAll = true) { /** @var RetailcrmAdminAbstractController $controller */ foreach (self::ADMIN_CONTROLLERS as $controller) { $tabId = $controller::getId(); - if (!$tabId) { + if (!$tabId || (!$forceAll && !is_subclass_of($controller, RetailcrmModuleDisablingAware::class))) { continue; } @@ -354,9 +354,18 @@ class RetailCRM extends Module public function disable($force_all = false) { - return parent::disable($force_all) - && $this->uninstallTab() - ; + if (!parent::disable($force_all)) { + return false; + } + + $sql = 'SELECT COUNT(`id_shop`) FROM `' . _DB_PREFIX_ . 'module_shop` + WHERE `id_module` = ' . (int) $this->id; + + if ('0' === Db::getInstance($sql)->getValue($sql)) { + return $this->uninstallTab(false); + } + + return true; } public function installDB()