Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable non native modules on PS8.0 and onward #498

Merged
merged 8 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
matthieu-rolland marked this conversation as resolved.
Show resolved Hide resolved
$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 @@ -54,6 +54,8 @@ class ModuleAdapter

private $commandBus;

private $moduleRepository;

matthieu-rolland marked this conversation as resolved.
Show resolved Hide resolved
public function __construct($db, $translator, $modulesPath, $tempPath, $upgradeVersion, ZipAction $zipAction, SymfonyAdapter $symfonyAdapter)
{
$this->db = $db;
Expand Down Expand Up @@ -99,6 +101,21 @@ public function getCommandBus()
return $this->commandBus;
}

/**
* Available since PrestaShop 8.0
*/
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