From 9a22f9e6244855a83c25e4efd2d1838314403299 Mon Sep 17 00:00:00 2001 From: matthieu-rolland Date: Wed, 17 Aug 2022 14:30:45 +0200 Subject: [PATCH] disabled non native modules on PS8.0 and onward --- .../CoreUpgrader/CoreUpgrader80.php | 21 +++++++++++++++++++ classes/UpgradeTools/ModuleAdapter.php | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php index 7fa6de3219..79f6951dc5 100644 --- a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php +++ b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php @@ -31,6 +31,7 @@ use PrestaShop\Module\AutoUpgrade\UpgradeException; use PrestaShop\PrestaShop\Core\CommandBus\CommandBusInterface; use PrestaShop\PrestaShop\Core\Domain\MailTemplate\Command\GenerateThemeMailTemplatesCommand; +use PrestaShop\PrestaShop\Core\Domain\Module\Command\BulkToggleModuleStatusCommand; use PrestaShop\PrestaShop\Core\Exception\CoreException; class CoreUpgrader80 extends CoreUpgrader @@ -100,4 +101,24 @@ 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()); + } + } } diff --git a/classes/UpgradeTools/ModuleAdapter.php b/classes/UpgradeTools/ModuleAdapter.php index b158701efe..b1daa82b13 100644 --- a/classes/UpgradeTools/ModuleAdapter.php +++ b/classes/UpgradeTools/ModuleAdapter.php @@ -54,6 +54,8 @@ class ModuleAdapter private $commandBus; + private $moduleRepository; + public function __construct($db, $translator, $modulesPath, $tempPath, $upgradeVersion, ZipAction $zipAction, SymfonyAdapter $symfonyAdapter) { $this->db = $db; @@ -99,6 +101,23 @@ public function getCommandBus() return $this->commandBus; } + /** + * Available since PrestaShop 8.0 + * + * @return \PrestaShop\PrestaShop\Adapter\Module\Repository\ModuleRepository + */ + public function getModuleRepository() + { + if (null === $this->moduleRepository) { + $this->moduleRepository = $this->symfonyAdapter + ->initAppKernel() + ->getContainer() + ->get('prestashop.adapter.module.repository.module_repository'); + } + + return $this->moduleRepository; + } + /** * Upgrade action, disabling all modules not made by PrestaShop. *