diff --git a/classes/Commands/CreateBackupCommand.php b/classes/Commands/CreateBackupCommand.php index 760e6dca4..70fa003b1 100644 --- a/classes/Commands/CreateBackupCommand.php +++ b/classes/Commands/CreateBackupCommand.php @@ -56,6 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int try { $this->setupEnvironment($input, $output); + $this->upgradeContainer->getFileConfigurationStorage()->cleanAllBackupFiles(); $controller = new AllBackupTasks($this->upgradeContainer); $controller->init(); $exitCode = $controller->run(); diff --git a/classes/Commands/RestoreCommand.php b/classes/Commands/RestoreCommand.php index 40a543f0d..414644a9a 100644 --- a/classes/Commands/RestoreCommand.php +++ b/classes/Commands/RestoreCommand.php @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int return ExitCode::SUCCESS; } } - + $this->upgradeContainer->getFileConfigurationStorage()->cleanAllRestoreFiles(); $controller = new AllRestoreTasks($this->upgradeContainer); $controller->setOptions([ 'backup' => $backup, diff --git a/classes/Commands/UpdateCommand.php b/classes/Commands/UpdateCommand.php index 32fb32582..e9b09c453 100644 --- a/classes/Commands/UpdateCommand.php +++ b/classes/Commands/UpdateCommand.php @@ -33,6 +33,7 @@ use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\Task\Runner\AllUpdateTasks; +use PrestaShop\Module\AutoUpgrade\Task\TaskName; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -56,10 +57,9 @@ protected function configure(): void ->addArgument('admin-dir', InputArgument::REQUIRED, 'The admin directory name.') ->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 ('local' / 'online')") + ->addOption('channel', null, InputOption::VALUE_REQUIRED, "Selects what update to run ('" . UpgradeConfiguration::CHANNEL_LOCAL . "' / '" . UpgradeConfiguration::CHANNEL_ONLINE . "')") ->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 (Default: UpgradeNow, see ' . DeveloperDocumentation::DEV_DOC_UPGRADE_CLI_URL . ' for other values available)') - ->addOption('data', null, InputOption::VALUE_REQUIRED, 'Advanced users only. Contains the state of the update process encoded in base64'); + ->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)'); } /** @@ -77,9 +77,16 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int try { $this->setupEnvironment($input, $output); - // in the case of commands containing the update status, it is not necessary to update the configuration - // also we do not want to repeat the update of the config in the recursive commands - if ($input->getOption('data') === null) { + $action = $input->getOption('action'); + + $isFirstUpdateProcess = $action === null || $action === TaskName::TASK_UPDATE_INITIALIZATION; + if ($isFirstUpdateProcess) { + $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) { $configPath = $input->getOption('config-file-path'); $exitCode = $this->loadConfiguration($configPath, $this->upgradeContainer); if ($exitCode !== ExitCode::SUCCESS) { @@ -91,8 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int $this->logger->debug('Starting the update process.'); $controller = new AllUpdateTasks($this->upgradeContainer); $controller->setOptions([ - 'data' => $input->getOption('data'), - 'action' => $input->getOption('action'), + 'action' => $action, UpgradeConfiguration::CHANNEL => $input->getOption('channel'), ]); $controller->init(); @@ -125,15 +131,10 @@ private function chainCommand(OutputInterface $output): int if (preg_match('/--action=(\S+)/', $lastInfo, $actionMatches)) { $action = $actionMatches[1]; $this->logger->debug('Action parameter found: ' . $action); - } - - if (preg_match('/--data=(\S+)/', $lastInfo, $dataMatches)) { - $data = $dataMatches[1]; - $this->logger->debug('Data parameter found: ' . $data); - } - if (empty($action) || empty($data)) { + } else { throw new InvalidArgumentException('The command does not contain the necessary information to continue the update process.'); } + $new_string = str_replace('INFO - $ ', '', $lastInfo); $decorationParam = $output->isDecorated() ? ' --ansi' : ''; system('php ' . $new_string . $decorationParam, $exitCode); diff --git a/classes/Task/AbstractTask.php b/classes/Task/AbstractTask.php index 48e9c0c32..e2f8c5bb1 100644 --- a/classes/Task/AbstractTask.php +++ b/classes/Task/AbstractTask.php @@ -105,14 +105,6 @@ public function __construct(UpgradeContainer $container) } } - /** - * @return string base64 encoded data from AjaxResponse - */ - public function getEncodedResponse(): string - { - return base64_encode($this->getJsonResponse()); - } - /** * @return string Json encoded data from AjaxResponse */ diff --git a/classes/Task/Runner/AllUpdateTasks.php b/classes/Task/Runner/AllUpdateTasks.php index 13d4d8985..6c32c33be 100644 --- a/classes/Task/Runner/AllUpdateTasks.php +++ b/classes/Task/Runner/AllUpdateTasks.php @@ -74,10 +74,6 @@ public function setOptions(array $options): void $this->container->getUpgradeConfiguration()->merge($config); } - - if (!empty($options['data'])) { - $this->container->getState()->importFromEncodedData($options['data']); - } } /** @@ -101,15 +97,11 @@ protected function checkIfRestartRequested(AjaxResponse $response): bool $this->logger->info('Restart requested. Please run the following command to continue your upgrade:'); $args = $_SERVER['argv']; foreach ($args as $key => $arg) { - if ( - strpos($arg, '--data') === 0 - || strpos($arg, '--action') === 0 - || strpos($arg, '--config-file-path') === 0 - ) { + if (strpos($arg, '--action') === 0 || strpos($arg, '--config-file-path') === 0) { unset($args[$key]); } } - $this->logger->info('$ ' . implode(' ', $args) . ' --action=' . $response->getNext() . ' --data=' . $this->getEncodedResponse()); + $this->logger->info('$ ' . implode(' ', $args) . ' --action=' . $response->getNext()); return true; } diff --git a/classes/Task/Runner/SingleTask.php b/classes/Task/Runner/SingleTask.php index 0be4d6796..1197ff33b 100644 --- a/classes/Task/Runner/SingleTask.php +++ b/classes/Task/Runner/SingleTask.php @@ -39,10 +39,6 @@ public function setOptions(array $options): void if (!empty($options['action'])) { $this->step = $options['action']; } - - if (!empty($options['data'])) { - $this->container->getState()->importFromEncodedData($options['data']); - } } protected function canContinue(): bool diff --git a/controllers/admin/AdminSelfUpgradeController.php b/controllers/admin/AdminSelfUpgradeController.php index 5dd36923d..0ba98302e 100644 --- a/controllers/admin/AdminSelfUpgradeController.php +++ b/controllers/admin/AdminSelfUpgradeController.php @@ -295,6 +295,8 @@ public function init() if (!$this->ajax) { // removing temporary files before init state to make sure state is already available $this->upgradeContainer->getFileConfigurationStorage()->cleanAllUpdateFiles(); + $this->upgradeContainer->getFileConfigurationStorage()->cleanAllBackupFiles(); + $this->upgradeContainer->getFileConfigurationStorage()->cleanAllRestoreFiles(); } if (!$this->upgradeContainer->getState()->isInitialized()) {