Skip to content

Commit

Permalink
Merge pull request PrestaShop#1042 from M0rgan01/add-update-options
Browse files Browse the repository at this point in the history
[CLI] Add new options for update command
  • Loading branch information
M0rgan01 authored Dec 3, 2024
2 parents ef62f4b + 068908e commit b6b7e37
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
32 changes: 26 additions & 6 deletions classes/Commands/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ protected function configure(): void
->addOption('chain', null, InputOption::VALUE_NONE, 'True by default. Allows you to chain update commands automatically. The command will continue executing subsequent tasks without requiring manual intervention to restart the process.')
->addOption('no-chain', null, InputOption::VALUE_NONE, 'Prevents chaining of update commands. The command will execute a task and then stop, logging the next command that needs to be run. You will need to manually restart the process to continue with the next step.')
->addOption('channel', null, InputOption::VALUE_REQUIRED, "Selects what update to run ('" . UpgradeConfiguration::CHANNEL_LOCAL . "' / '" . UpgradeConfiguration::CHANNEL_ONLINE . "')")
->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')
->addOption('disable-non-native-modules', null, InputOption::VALUE_REQUIRED, 'Disable all modules installed after the store creation (1 for yes, 0 for no)')
->addOption('regenerate-email-templates', null, InputOption::VALUE_REQUIRED, "Regenerate email templates. If you've customized email templates, your changes will be lost if you activate this option (1 for yes, 0 for no)")
->addOption('disable-all-overrides', null, InputOption::VALUE_REQUIRED, 'Overriding is a way to replace business behaviors (class files and controller files) to target only one method or as many as you need. This option disables all classes & controllers overrides, allowing you to avoid conflicts during and after updates (1 for yes, 0 for no)')
->addOption('config-file-path', null, InputOption::VALUE_REQUIRED, 'Configuration file location for update.')
->addOption('action', null, InputOption::VALUE_REQUIRED, 'Advanced users only. Sets the step you want to start from. Only the "' . TaskName::TASK_UPDATE_INITIALIZATION . '" task updates the configuration. (Default: ' . TaskName::TASK_UPDATE_INITIALIZATION . ', see ' . DeveloperDocumentation::DEV_DOC_UPGRADE_CLI_URL . ' for other values available)');
}
Expand All @@ -79,14 +84,12 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int

$action = $input->getOption('action');

$isFirstUpdateProcess = $action === null || $action === TaskName::TASK_UPDATE_INITIALIZATION;
if ($isFirstUpdateProcess) {
// if we are in the 1st step of the update, we update the configuration
if ($action === null || $action === TaskName::TASK_UPDATE_INITIALIZATION) {
$this->logger->debug('Cleaning previous state files.');
$this->upgradeContainer->getFileConfigurationStorage()->cleanAllUpdateFiles();
}

// if we are in the 1st step of the update, we update the configuration
if ($isFirstUpdateProcess) {
$this->processConsoleInputConfiguration($input);
$configPath = $input->getOption('config-file-path');
$exitCode = $this->loadConfiguration($configPath);
if ($exitCode !== ExitCode::SUCCESS) {
Expand All @@ -99,7 +102,6 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
$controller = new AllUpdateTasks($this->upgradeContainer);
$controller->setOptions([
'action' => $action,
UpgradeConfiguration::CHANNEL => $input->getOption('channel'),
]);
$controller->init();
$exitCode = $controller->run();
Expand Down Expand Up @@ -144,4 +146,22 @@ private function chainCommand(OutputInterface $output): int

return ExitCode::SUCCESS;
}

private function processConsoleInputConfiguration(InputInterface $input): void
{
$options = [
UpgradeConfiguration::CHANNEL => 'channel',
UpgradeConfiguration::ARCHIVE_ZIP => 'zip',
UpgradeConfiguration::ARCHIVE_XML => 'xml',
UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT => 'disable-non-native-modules',
UpgradeConfiguration::PS_AUTOUP_REGEN_EMAIL => 'regenerate-email-templates',
UpgradeConfiguration::PS_DISABLE_OVERRIDES => 'disable-all-overrides',
];
foreach ($options as $configKey => $optionName) {
$optionValue = $input->getOption($optionName);
if ($optionValue !== null) {
$this->consoleInputConfiguration[$configKey] = $optionValue;
}
}
}
}
15 changes: 0 additions & 15 deletions classes/Task/Runner/AllUpdateTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@

use Exception;
use PrestaShop\Module\AutoUpgrade\AjaxResponse;
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\Task\TaskName;
use UnexpectedValueException;

/**
* Execute the whole upgrade process in a single request.
Expand Down Expand Up @@ -61,19 +59,6 @@ public function setOptions(array $options): void
if (!empty($options['action'])) {
$this->step = $options['action'];
}

if (!empty($options[UpgradeConfiguration::CHANNEL])) {
$config = [
UpgradeConfiguration::CHANNEL => $options[UpgradeConfiguration::CHANNEL],
];
$error = $this->container->getConfigurationValidator()->validate($config);

if (!empty($error)) {
throw new UnexpectedValueException(reset($error)['message']);
}

$this->container->getUpgradeConfiguration()->merge($config);
}
}

/**
Expand Down

0 comments on commit b6b7e37

Please sign in to comment.