diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5060b84b4..fa832f327 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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 diff --git a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php index 7fa6de321..1989a0a18 100644 --- a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php +++ b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php @@ -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; @@ -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); + } } diff --git a/classes/UpgradeTools/ModuleAdapter.php b/classes/UpgradeTools/ModuleAdapter.php index b158701ef..d291ae713 100644 --- a/classes/UpgradeTools/ModuleAdapter.php +++ b/classes/UpgradeTools/ModuleAdapter.php @@ -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. * diff --git a/tests/phpstan/phpstan-1.6.1.18.neon b/tests/phpstan/phpstan-1.6.1.18.neon index fb1b3ab9e..eaee787c9 100644 --- a/tests/phpstan/phpstan-1.6.1.18.neon +++ b/tests/phpstan/phpstan-1.6.1.18.neon @@ -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.#' diff --git a/tests/phpstan/phpstan-1.7.2.5.neon b/tests/phpstan/phpstan-1.7.2.5.neon index c89b3643a..48756f7cb 100644 --- a/tests/phpstan/phpstan-1.7.2.5.neon +++ b/tests/phpstan/phpstan-1.7.2.5.neon @@ -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.#' diff --git a/tests/phpstan/phpstan-1.7.3.4.neon b/tests/phpstan/phpstan-1.7.3.4.neon index c89b3643a..48756f7cb 100644 --- a/tests/phpstan/phpstan-1.7.3.4.neon +++ b/tests/phpstan/phpstan-1.7.3.4.neon @@ -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.#' diff --git a/tests/phpstan/phpstan-1.7.4.4.neon b/tests/phpstan/phpstan-1.7.4.4.neon index aa06b6516..a6af43d6d 100644 --- a/tests/phpstan/phpstan-1.7.4.4.neon +++ b/tests/phpstan/phpstan-1.7.4.4.neon @@ -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.#' diff --git a/tests/phpstan/phpstan-1.7.5.1.neon b/tests/phpstan/phpstan-1.7.5.1.neon index f228e2ad0..315f0a9a4 100644 --- a/tests/phpstan/phpstan-1.7.5.1.neon +++ b/tests/phpstan/phpstan-1.7.5.1.neon @@ -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.#' diff --git a/tests/phpstan/phpstan-1.7.6.neon b/tests/phpstan/phpstan-1.7.6.neon index 45eed3c13..94c20235c 100644 --- a/tests/phpstan/phpstan-1.7.6.neon +++ b/tests/phpstan/phpstan-1.7.6.neon @@ -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.#' diff --git a/tests/phpstan/phpstan-1.7.7.neon b/tests/phpstan/phpstan-1.7.7.neon index 5aba843bc..302d07712 100644 --- a/tests/phpstan/phpstan-1.7.7.neon +++ b/tests/phpstan/phpstan-1.7.7.neon @@ -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.#' diff --git a/tests/phpstan/phpstan-1.7.8.neon b/tests/phpstan/phpstan-1.7.8.neon index 94bf1b5eb..f7fd6891a 100644 --- a/tests/phpstan/phpstan-1.7.8.neon +++ b/tests/phpstan/phpstan-1.7.8.neon @@ -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.#' diff --git a/tests/phpstan/phpstan-8.0.0-beta.1.neon b/tests/phpstan/phpstan-8.0.0-beta.1.neon new file mode 100644 index 000000000..bed239fdf --- /dev/null +++ b/tests/phpstan/phpstan-8.0.0-beta.1.neon @@ -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 diff --git a/tests/phpstan/phpstan-latest.neon b/tests/phpstan/phpstan-latest.neon index ebbff783a..302d07712 100644 --- a/tests/phpstan/phpstan-latest.neon +++ b/tests/phpstan/phpstan-latest.neon @@ -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.#' diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index 5e9dadfe8..ca9525924 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -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 diff --git a/upgrade/php/deactivate_custom_modules.php b/upgrade/php/deactivate_custom_modules.php index 1a7230ae1..4af64577e 100644 --- a/upgrade/php/deactivate_custom_modules.php +++ b/upgrade/php/deactivate_custom_modules.php @@ -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[] = '""'; @@ -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); +}