diff --git a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php index 79f6951dc..30f8e9cdb 100644 --- a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php +++ b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php @@ -33,6 +33,7 @@ use PrestaShop\PrestaShop\Core\Domain\MailTemplate\Command\GenerateThemeMailTemplatesCommand; use PrestaShop\PrestaShop\Core\Domain\Module\Command\BulkToggleModuleStatusCommand; use PrestaShop\PrestaShop\Core\Exception\CoreException; +use PrestaShop\PrestaShop\Adapter\Module\Repository\ModuleRepository; class CoreUpgrader80 extends CoreUpgrader { @@ -102,23 +103,9 @@ protected function upgradeLanguage($lang) // TODO: Update AdminTranslationsController::addNewTabs to install tabs translated } - /** - * Ask the core to disable the modules not coming from PrestaShop. - */ protected function disableCustomModules() { - try { - $bulkToggleModuleStatusCommand = new BulkToggleModuleStatusCommand( - $this->container->getModuleAdapter()->getModuleRepository()->getNonNativeModules(), - false - ); - - /** @var CommandBusInterface $commandBus */ - $commandBus = $this->container->getModuleAdapter()->getCommandBus(); - - $commandBus->handle($bulkToggleModuleStatusCommand); - } catch (\Exception $e) { - throw new UpgradeException($e->getMessage()); - } + $moduleRepository = new ModuleRepository(_PS_ROOT_DIR_, _PS_MODULE_DIR_); + $this->container->getModuleAdapter()->disableNonNativeModules80($this->pathToUpgradeScripts, $moduleRepository); } } diff --git a/classes/UpgradeTools/ModuleAdapter.php b/classes/UpgradeTools/ModuleAdapter.php index db1021131..46591df89 100644 --- a/classes/UpgradeTools/ModuleAdapter.php +++ b/classes/UpgradeTools/ModuleAdapter.php @@ -129,6 +129,12 @@ public function disableNonNativeModules($pathToUpgradeScripts) deactivate_custom_modules(); } + public function disableNonNativeModules80($pathToUpgradeScripts, $moduleRepository) + { + require_once $pathToUpgradeScripts . 'php/deactivate_custom_modules.php'; + deactivate_custom_modules80($moduleRepository); + } + /** * list modules to upgrade and save them in a serialized array in $this->toUpgradeModuleList. * diff --git a/upgrade/php/deactivate_custom_modules.php b/upgrade/php/deactivate_custom_modules.php index 1a7230ae1..b9af03f79 100644 --- a/upgrade/php/deactivate_custom_modules.php +++ b/upgrade/php/deactivate_custom_modules.php @@ -95,3 +95,39 @@ function deactivate_custom_modules() return $return; } + +function deactivate_custom_modules80($moduleRepository) +{ + $nonNativeModulesList = $moduleRepository->getNonNativeModules(); + + $return = Db::getInstance()->execute( + 'UPDATE `' . _DB_PREFIX_ . 'module` SET `active` = 0 WHERE `name` IN (' . implode(',', array_map('add_quotes', $nonNativeModulesList)) . ')' + ); + + $nonNativeModules = \Db::getInstance()->executeS(' + SELECT * + FROM `' . _DB_PREFIX_ . 'module` m + WHERE name IN (' . implode(',', array_map('add_quotes', $nonNativeModulesList)) . ') '); + + if (!is_array($nonNativeModules) || empty($nonNativeModules)) { + return $return; + } + + $toBeUninstalled = []; + foreach ($nonNativeModules as $k => $aModule) { + $toBeUninstalled[] = (int) $aModule['id_module']; + } + + if (empty($toBeUninstalled)) { + return $return; + } + + $sql = 'DELETE FROM `' . _DB_PREFIX_ . 'module_shop` WHERE `id_module` IN (' . implode(',', array_map('add_quotes', $toBeUninstalled)) . ') '; + $return &= Db::getInstance()->execute($sql); + + return $return; +} + +function add_quotes($str) { + return sprintf("'%s'", $str); +}