Skip to content

Commit

Permalink
Merge pull request #498 from matthieu-rolland/disable-non-native-modules
Browse files Browse the repository at this point in the history
Disable non native modules on PS8.0 and onward
  • Loading branch information
atomiix authored Sep 5, 2022
2 parents 29ad915 + d389a26 commit efe996a
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
presta-versions: ['1.6.1.18', '1.7.2.5', '1.7.3.4', '1.7.4.4', '1.7.5.1', '1.7.6', '1.7.7', '1.7.8', 'latest']
presta-versions: ['1.6.1.18', '1.7.2.5', '1.7.3.4', '1.7.4.4', '1.7.5.1', '1.7.6', '1.7.7', '1.7.8', 'latest', '8.0.0-beta.1']
steps:
- name: Checkout
uses: actions/checkout@v2.0.0
Expand Down
7 changes: 7 additions & 0 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace PrestaShop\Module\AutoUpgrade\UpgradeTools\CoreUpgrader;

use PrestaShop\Module\AutoUpgrade\UpgradeException;
use PrestaShop\PrestaShop\Adapter\Module\Repository\ModuleRepository;
use PrestaShop\PrestaShop\Core\CommandBus\CommandBusInterface;
use PrestaShop\PrestaShop\Core\Domain\MailTemplate\Command\GenerateThemeMailTemplatesCommand;
use PrestaShop\PrestaShop\Core\Exception\CoreException;
Expand Down Expand Up @@ -100,4 +101,10 @@ protected function upgradeLanguage($lang)

// TODO: Update AdminTranslationsController::addNewTabs to install tabs translated
}

protected function disableCustomModules()
{
$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 @@ -112,6 +112,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
1 change: 0 additions & 1 deletion tests/phpstan/phpstan-1.6.1.18.neon
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ parameters:
- '#Call to method assign\(\) on an unknown class Smarty.#'
- '#Call to method fetch\(\) on an unknown class Smarty.#'
- '#Call to method getContainer\(\) on an unknown class AppKernel.#'
- '#Function deactivate_custom_modules not found.#'
- '#PrestaShop\\PrestaShop\\Adapter\\Module\\ModuleDataUpdater#'
- '#Property ModuleCore::\$version \(float\) does not accept string.#'
- '#Return typehint of method PrestaShop\\Module\\AutoUpgrade\\UpgradeTools\\ModuleAdapter::getCommandBus\(\) has invalid type PrestaShop\\PrestaShop\\Core\\CommandBus\\TacticianCommandBusAdapter.#'
1 change: 0 additions & 1 deletion tests/phpstan/phpstan-1.7.2.5.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ parameters:
- '#Call to method loadClassCache\(\) on an unknown class AppKernel.#'
- '#Caught class PrestaShop\\PrestaShop\\Core\\Exception\\CoreException not found.#'
- '#Class AppKernel not found.#'
- '#Function deactivate_custom_modules not found.#'
- '#Instantiated class AppKernel not found.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Domain\\Theme\\ValueObject\\ThemeName not found.#'
- '#PHPDoc tag @var for variable \$commandBus contains unknown class PrestaShop\\PrestaShop\\Core\\CommandBus\\CommandBusInterface.#'
Expand Down
1 change: 0 additions & 1 deletion tests/phpstan/phpstan-1.7.3.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ parameters:
- '#Call to method loadClassCache\(\) on an unknown class AppKernel.#'
- '#Caught class PrestaShop\\PrestaShop\\Core\\Exception\\CoreException not found.#'
- '#Class AppKernel not found.#'
- '#Function deactivate_custom_modules not found.#'
- '#Instantiated class AppKernel not found.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Domain\\Theme\\ValueObject\\ThemeName not found.#'
- '#PHPDoc tag @var for variable \$commandBus contains unknown class PrestaShop\\PrestaShop\\Core\\CommandBus\\CommandBusInterface.#'
Expand Down
1 change: 0 additions & 1 deletion tests/phpstan/phpstan-1.7.4.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ parameters:
- '#Call to method getMessage\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Exception\\CoreException.#'
- '#Call to method handle\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\CommandBus\\CommandBusInterface.#'
- '#Caught class PrestaShop\\PrestaShop\\Core\\Exception\\CoreException not found.#'
- '#Function deactivate_custom_modules not found.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Domain\\Theme\\ValueObject\\ThemeName not found.#'
- '#PHPDoc tag @var for variable \$commandBus contains unknown class PrestaShop\\PrestaShop\\Core\\CommandBus\\CommandBusInterface.#'
- '#Property ModuleCore::\$version \(float\) does not accept string.#'
Expand Down
1 change: 0 additions & 1 deletion tests/phpstan/phpstan-1.7.5.1.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ parameters:
- '#Access to an undefined property Autoupgrade::\$bootstrap.#'
- '#Access to an undefined property Module::\$installed.#'
- '#Call to an undefined static method ConfigurationTest::test_memory_limit\(\).#'
- '#Function deactivate_custom_modules not found.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Domain\\Theme\\ValueObject\\ThemeName not found.#'
- '#Property ModuleCore::\$version \(float\) does not accept string.#'
1 change: 0 additions & 1 deletion tests/phpstan/phpstan-1.7.6.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ parameters:
- '#Access to an undefined property Module::\$installed.#'
- '#Call to an undefined static method ConfigurationTest::test_memory_limit\(\).#'
- '#Call to method fetchLocale\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Cldr\\Update.#'
- '#Function deactivate_custom_modules not found.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Cldr\\Update not found.#'
- '#Parameter \#1 \$id_hook of method ModuleCore::updatePosition\(\) expects bool, int given.#'
- '#Property ModuleCore::\$version \(float\) does not accept string.#'
Expand Down
1 change: 0 additions & 1 deletion tests/phpstan/phpstan-1.7.7.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ parameters:
ignoreErrors:
- '#Access to an undefined property Module::\$installed.#'
- '#Call to method fetchLocale\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Cldr\\Update.#'
- '#Function deactivate_custom_modules not found.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Cldr\\Update not found.#'
1 change: 0 additions & 1 deletion tests/phpstan/phpstan-1.7.8.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ parameters:
ignoreErrors:
- '#Access to an undefined property Module::\$installed.#'
- '#Call to method fetchLocale\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Cldr\\Update.#'
- '#Function deactivate_custom_modules not found.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Cldr\\Update not found.#'

8 changes: 8 additions & 0 deletions tests/phpstan/phpstan-8.0.0-beta.1.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
excludes_analyse:
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader17.php
- ./../../classes/Twig/TransFilterExtension.php
- ./../../classes/UpgradeContainer.php
3 changes: 2 additions & 1 deletion tests/phpstan/phpstan-latest.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
excludes_analyse:
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
ignoreErrors:
- '#Access to an undefined property Module::\$installed.#'
- '#Call to method fetchLocale\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Cldr\\Update.#'
- '#Function deactivate_custom_modules not found.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Cldr\\Update not found.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ parameters:
paths:
# From PHPStan 0.12, paths to check are relative to the neon file
- ./../../classes
- ./../../upgrade/php/deactivate_custom_modules.php
- ./../../AdminSelfUpgrade.php
- ./../../ajax-upgradetab.php
- ./../../ajax-upgradetabconfig.php
Expand Down
39 changes: 38 additions & 1 deletion upgrade/php/deactivate_custom_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function deactivate_custom_modules()
$nativeModules = $nativeModules->modules;
}
$arrNativeModules = [];
if (is_array($nativeModules)) {
if (!empty($nativeModules)) {
foreach ($nativeModules as $nativeModulesType) {
if (in_array($nativeModulesType['type'], ['native', 'partner'])) {
$arrNativeModules[] = '""';
Expand Down Expand Up @@ -95,3 +95,40 @@ 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 efe996a

Please sign in to comment.