From 7b93bb202e5259ca1b7bb2aecef15c988d8689a5 Mon Sep 17 00:00:00 2001 From: morgan Date: Wed, 20 Nov 2024 11:40:42 +0100 Subject: [PATCH] Improve Check Requirements Command --- classes/Commands/CheckRequirementsCommand.php | 18 +++++++++++++++++- classes/Task/Miscellaneous/UpdateConfig.php | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/classes/Commands/CheckRequirementsCommand.php b/classes/Commands/CheckRequirementsCommand.php index 6ff4e47fd..feffd8236 100644 --- a/classes/Commands/CheckRequirementsCommand.php +++ b/classes/Commands/CheckRequirementsCommand.php @@ -28,9 +28,11 @@ namespace PrestaShop\Module\AutoUpgrade\Commands; use Exception; +use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; use PrestaShop\Module\AutoUpgrade\Services\DistributionApiService; use PrestaShop\Module\AutoUpgrade\Services\PhpVersionResolverService; use PrestaShop\Module\AutoUpgrade\Task\ExitCode; +use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -40,7 +42,7 @@ class CheckRequirementsCommand extends AbstractCommand { /** @var string */ - protected static $defaultName = 'update:check'; + protected static $defaultName = 'update:check-requirements'; const MODULE_CONFIG_DIR = 'autoupgrade'; /** @var UpgradeSelfCheck */ private $upgradeSelfCheck; @@ -55,6 +57,8 @@ protected function configure(): void ->setDescription('Check all prerequisites for an update.') ->setHelp('This command allows you to check the prerequisites necessary for the proper functioning of an update.') ->addOption('config-file-path', null, InputOption::VALUE_REQUIRED, 'Configuration file location for update.') + ->addOption('zip', null, InputOption::VALUE_REQUIRED, 'Sets the archive zip file for a local update.') + ->addOption('xml', null, InputOption::VALUE_REQUIRED, 'Sets the archive xml file for a local update.') ->addArgument('admin-dir', InputArgument::REQUIRED, 'The admin directory name.'); } @@ -67,6 +71,17 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int $this->setupContainer($input, $output); $this->output = $output; + $options = [ + UpgradeConfiguration::ARCHIVE_ZIP => 'zip', + UpgradeConfiguration::ARCHIVE_XML => 'xml', + ]; + foreach ($options as $configKey => $optionName) { + $optionValue = $input->getOption($optionName); + if ($optionValue !== null) { + $this->consoleInputConfiguration[$configKey] = $optionValue; + } + } + $configPath = $input->getOption('config-file-path'); $exitCode = $this->loadConfiguration($configPath); if ($exitCode !== ExitCode::SUCCESS) { @@ -77,6 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int $this->upgradeContainer->initPrestaShopAutoloader(); $this->upgradeContainer->initPrestaShopCore(); + $this->upgradeContainer->getState()->initDefault($this->upgradeContainer->getProperty(UpgradeContainer::PS_VERSION), $this->upgradeContainer->getUpgrader()->getDestinationVersion()); $distributionApiService = new DistributionApiService(); $phpVersionResolverService = new PhpVersionResolverService( diff --git a/classes/Task/Miscellaneous/UpdateConfig.php b/classes/Task/Miscellaneous/UpdateConfig.php index 304cc2bfa..83ea9c7d4 100644 --- a/classes/Task/Miscellaneous/UpdateConfig.php +++ b/classes/Task/Miscellaneous/UpdateConfig.php @@ -72,6 +72,12 @@ public function run(): int } } + // If no channel is specified, and there is a configuration relating to archive files, we deduce that the channel is local + $archiveFilesConfExist = isset($config[UpgradeConfiguration::ARCHIVE_XML]) || isset($config[UpgradeConfiguration::ARCHIVE_ZIP]); + if (!isset($config[UpgradeConfiguration::CHANNEL]) && $archiveFilesConfExist) { + $config[UpgradeConfiguration::CHANNEL] = UpgradeConfiguration::CHANNEL_LOCAL; + } + $isLocal = $config[UpgradeConfiguration::CHANNEL] === UpgradeConfiguration::CHANNEL_LOCAL; $error = $this->container->getConfigurationValidator()->validate($config);