From 57ae6d7cb42e220d37bbee32ab80bade384f1519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Hennes?= Date: Fri, 20 Jun 2025 21:33:56 +0200 Subject: [PATCH] #14 Fix compatibility with prestashop 9 --- README.md | 8 ++--- config/services.yml | 6 ++++ src/Commands/GeneratePatchCommand.php | 20 ++++++++--- src/Commands/ListUpgradableModulesCommand.php | 15 +++++--- src/Commands/ManageModulesCommand.php | 35 +++++++++++-------- src/Patch/Manager.php | 2 +- 6 files changed, 57 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 367a0f1..f4abce5 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ You can find more information about this module in the following articles (in Fr Compatibility --- -| Prestashop Version | Compatible | -|--------------------| ---------| -| 1.7.8.x | :heavy_check_mark: | -| 8.x | :heavy_check_mark: | +| Prestashop Version | Compatible | +|--------------------|---------------------------------------------------------------| +| 1.7.8.x | version 0.4.0 and under :heavy_check_mark: | +| 8.0,8.1 | version 0.4.0 and under, or with php 8.1 + :heavy_check_mark: | | 9.0 | In progress | diff --git a/config/services.yml b/config/services.yml index c771289..996359b 100644 --- a/config/services.yml +++ b/config/services.yml @@ -73,14 +73,20 @@ services: #Console commands hhennes.modulesmanager.manage.command: class: Hhennes\ModulesManager\Commands\ManageModulesCommand + arguments: + - '@hhennes.modulesmanager.manager' tags: - { name: console.command } hhennes.modulesmanager.upgradable.modules.list: class: Hhennes\ModulesManager\Commands\ListUpgradableModulesCommand + arguments: + - '@PrestaShop\PrestaShop\Core\Module\ModuleRepository' tags: - { name: console.command } hhennes.modulesmanager.upgrade.generate: class: Hhennes\ModulesManager\Commands\GeneratePatchCommand + arguments: + - '@hhennes.modulesmanager.patch.generator' tags: - { name: console.command } #Logger diff --git a/src/Commands/GeneratePatchCommand.php b/src/Commands/GeneratePatchCommand.php index c6bdbe8..940ed98 100644 --- a/src/Commands/GeneratePatchCommand.php +++ b/src/Commands/GeneratePatchCommand.php @@ -19,7 +19,8 @@ namespace Hhennes\ModulesManager\Commands; use Hhennes\ModulesManager\Change; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Hhennes\ModulesManager\Patch\Generator; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -27,8 +28,19 @@ /** * This command allow to generate an upgrade file (patch) from the command line */ -class GeneratePatchCommand extends ContainerAwareCommand +class GeneratePatchCommand extends Command { + /** + * @param Generator $patchGenerator + * @param string|null $name + */ + public function __construct( + private readonly Generator $patchGenerator, + ?string $name = null, + ) { + parent::__construct($name); + } + /** * {@inheritdoc} */ @@ -59,9 +71,7 @@ public function execute(InputInterface $input, OutputInterface $output): int ]; $changeIds = Change::getChangesByFilters($filters); if (count($changeIds)) { - /** @var \Hhennes\ModulesManager\Patch\Generator $patchGenerator */ - $patchGenerator = $this->getContainer()->get('hhennes.modulesmanager.patch.generator'); - $upgradeFileName = $patchGenerator->generateChangeFile($changeIds, date('Ymd-His') . '-patch'); + $upgradeFileName = $this->patchGenerator->generateChangeFile($changeIds, date('Ymd-His') . '-patch'); $output->writeln(sprintf('Upgrade file %s generated with success', $upgradeFileName)); } else { $output->writeln('No changes found for update, no files was generated'); diff --git a/src/Commands/ListUpgradableModulesCommand.php b/src/Commands/ListUpgradableModulesCommand.php index 51e84ab..e2b53da 100644 --- a/src/Commands/ListUpgradableModulesCommand.php +++ b/src/Commands/ListUpgradableModulesCommand.php @@ -18,13 +18,21 @@ namespace Hhennes\ModulesManager\Commands; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use PrestaShop\PrestaShop\Core\Module\ModuleRepositoryInterface; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class ListUpgradableModulesCommand extends ContainerAwareCommand +class ListUpgradableModulesCommand extends Command { + public function __construct( + private readonly ModuleRepositoryInterface $moduleRepository, + ?string $name = null, + ) { + parent::__construct($name); + } + /** * {@inheritdoc} */ @@ -62,8 +70,7 @@ public function execute(InputInterface $input, OutputInterface $output): int protected function getUpgradableModules(): array { $modulesNames = []; - $moduleRepository = $this->getContainer()->get('prestashop.core.admin.module.repository'); - $installedModules = $moduleRepository->getInstalledModules(); + $installedModules = $this->moduleRepository->getInstalledModules(); foreach ($installedModules as $installedModule) { if ($installedModule->canBeUpgraded()) { $modulesNames[] = $installedModule->get('name'); diff --git a/src/Commands/ManageModulesCommand.php b/src/Commands/ManageModulesCommand.php index 3334bda..d7ffe5e 100644 --- a/src/Commands/ManageModulesCommand.php +++ b/src/Commands/ManageModulesCommand.php @@ -19,8 +19,7 @@ namespace Hhennes\ModulesManager\Commands; use Hhennes\ModulesManager\Patch\Manager; -use Module; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -28,7 +27,7 @@ * This command is the main file of the module * It should be called during the CI/CD process to run the registered upgrades */ -class ManageModulesCommand extends ContainerAwareCommand +class ManageModulesCommand extends Command { /** @var string Upgrade module name */ protected string $moduleName = 'hhmodulesmanager'; @@ -41,6 +40,17 @@ class ManageModulesCommand extends ContainerAwareCommand /** @var false|\Module */ private $module; + /** + * @param Manager $manager + * @param string|null $name + */ + public function __construct( + private readonly Manager $manager, + ?string $name = null, + ) { + parent::__construct($name); + } + /** * {@inheritdoc} */ @@ -65,25 +75,21 @@ public function execute(InputInterface $input, OutputInterface $output): int try { $this->output = $output; $this->module = \Module::getInstanceByName($this->moduleName); - - /** @var Manager $manager */ - $manager = $this->getContainer()->get('hhennes.modulesmanager.manager'); - $output->writeln('Module Upgrade command launched'); $this->log('========================='); $this->log('Command Upgrade launched'); - $upgradeFiles = $manager->getUpgradeFiles(); - $appliedPatches = $manager->getAppliedPatches(); + $upgradeFiles = $this->manager->getUpgradeFiles(); + $appliedPatches = $this->manager->getAppliedPatches(); foreach ($upgradeFiles as $upgradeFile) { $patchName = $upgradeFile->getBasename('.yml'); if (!in_array($patchName, $appliedPatches)) { $this->output->writeln('Applying patch "' . $patchName . '"'); $this->log('Applying patch ' . $patchName); - $manager->applyPatch($upgradeFile, $patchName); + $this->manager->applyPatch($upgradeFile, $patchName); } } - $this->logAndRenderResult($output, $manager); + $this->logAndRenderResult($output); $output->writeln('End of process'); $this->log('End of upgrade process'); } catch (\Throwable $e) { @@ -104,14 +110,13 @@ public function execute(InputInterface $input, OutputInterface $output): int * Log and display the result of the run of the command * * @param OutputInterface $output - * @param Manager $manager * * @return void */ - protected function logAndRenderResult(OutputInterface $output, Manager $manager): void + protected function logAndRenderResult(OutputInterface $output): void { - $this->success = array_merge($this->success, $manager->getSuccess()); - $this->errors = array_merge($this->errors, $manager->getErrors()); + $this->success = array_merge($this->success, $this->manager->getSuccess()); + $this->errors = array_merge($this->errors, $this->manager->getErrors()); if (count($this->success)) { $this->log('=== Success Messages'); foreach ($this->success as $success) { diff --git a/src/Patch/Manager.php b/src/Patch/Manager.php index 49e833b..209a9ec 100644 --- a/src/Patch/Manager.php +++ b/src/Patch/Manager.php @@ -34,7 +34,7 @@ class Manager * @param UpgraderFactory $upgraderFactory */ public function __construct( - UpgraderFactory $upgraderFactory + UpgraderFactory $upgraderFactory, ) { $this->upgraderFactory = $upgraderFactory; }