Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-rolland committed Aug 30, 2022
1 parent c30773c commit 8fbecfd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
19 changes: 3 additions & 16 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions classes/UpgradeTools/ModuleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
36 changes: 36 additions & 0 deletions upgrade/php/deactivate_custom_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 8fbecfd

Please sign in to comment.