Skip to content

Commit

Permalink
disabled non native modules on PS8.0 and onward
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-rolland committed Aug 17, 2022
1 parent 13ac643 commit b0bdac7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
}
17 changes: 17 additions & 0 deletions classes/UpgradeTools/ModuleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,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.
*
Expand Down

0 comments on commit b0bdac7

Please sign in to comment.