diff --git a/classes/Commands/AbstractCommand.php b/classes/Commands/AbstractCommand.php index 0b401b0c4..15d4feb28 100644 --- a/classes/Commands/AbstractCommand.php +++ b/classes/Commands/AbstractCommand.php @@ -98,6 +98,13 @@ protected function setupEnvironment(InputInterface $input, OutputInterface $outp */ protected function loadConfiguration(?string $configPath): int { + $updateConfiguration = $this->upgradeContainer->getUpdateConfiguration(); + if (!$updateConfiguration->hasAllTheShopConfiguration()) { + $this->upgradeContainer->initPrestaShopCore(); + $this->upgradeContainer->getPrestaShopConfiguration()->fillInUpdateConfiguration($updateConfiguration); + } + $this->upgradeContainer->getConfigurationStorage()->save($updateConfiguration); + $controller = new UpdateConfig($this->upgradeContainer); $configurationData = []; diff --git a/classes/Commands/CheckRequirementsCommand.php b/classes/Commands/CheckRequirementsCommand.php index 630caaf92..0561d3893 100644 --- a/classes/Commands/CheckRequirementsCommand.php +++ b/classes/Commands/CheckRequirementsCommand.php @@ -32,7 +32,6 @@ use PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; 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; @@ -88,7 +87,6 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int $this->upgradeContainer->initPrestaShopAutoloader(); $this->upgradeContainer->initPrestaShopCore(); - $this->upgradeContainer->getUpdateState()->initDefault($this->upgradeContainer->getProperty(UpgradeContainer::PS_VERSION), $this->upgradeContainer->getUpgrader()->getDestinationVersion()); $output->writeln('Result of prerequisite checks:'); $this->exitCode = ExitCode::SUCCESS; diff --git a/classes/Commands/CreateBackupCommand.php b/classes/Commands/CreateBackupCommand.php index 32ed560c9..09585c348 100644 --- a/classes/Commands/CreateBackupCommand.php +++ b/classes/Commands/CreateBackupCommand.php @@ -66,7 +66,6 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int $this->loadConfiguration($configPath); - $this->upgradeContainer->getFileStorage()->cleanAllBackupFiles(); $controller = new AllBackupTasks($this->upgradeContainer); $controller->init(); $exitCode = $controller->run(); diff --git a/classes/Commands/RestoreCommand.php b/classes/Commands/RestoreCommand.php index a166cad82..58f1a74e1 100644 --- a/classes/Commands/RestoreCommand.php +++ b/classes/Commands/RestoreCommand.php @@ -77,7 +77,6 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int return ExitCode::SUCCESS; } } - $this->upgradeContainer->getFileStorage()->cleanAllRestoreFiles(); $controller = new AllRestoreTasks($this->upgradeContainer); $controller->setOptions([ RestoreConfiguration::BACKUP_NAME => $backup, diff --git a/classes/Commands/UpdateCommand.php b/classes/Commands/UpdateCommand.php index d88e864c1..4abce466b 100644 --- a/classes/Commands/UpdateCommand.php +++ b/classes/Commands/UpdateCommand.php @@ -35,6 +35,7 @@ use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\Task\Runner\AllUpdateTasks; use PrestaShop\Module\AutoUpgrade\Task\TaskName; +use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -87,8 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int // 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->getFileStorage()->cleanAllUpdateFiles(); + $this->logger->debug('Cleaning previous configuration file.'); $this->upgradeContainer->getFileStorage()->clean(UpgradeFileNames::UPDATE_CONFIG_FILENAME); $this->processConsoleInputConfiguration($input); @@ -97,6 +97,13 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int if ($exitCode !== ExitCode::SUCCESS) { return $exitCode; } + } else { + $updateState = $this->upgradeContainer->getUpdateState(); + // In the special case the user inits the process from a specific task that is not the initialization, + // we need to initialize the state manually. + if (!$updateState->isInitialized()) { + $updateState->initDefault($this->upgradeContainer->getProperty(UpgradeContainer::PS_VERSION), $this->upgradeContainer->getUpgrader(), $this->upgradeContainer->getUpdateConfiguration()); + } } $this->logger->debug('Configuration loaded successfully.'); diff --git a/classes/Parameters/UpgradeConfiguration.php b/classes/Parameters/UpgradeConfiguration.php index 8758336fa..f046b3c78 100644 --- a/classes/Parameters/UpgradeConfiguration.php +++ b/classes/Parameters/UpgradeConfiguration.php @@ -49,6 +49,8 @@ class UpgradeConfiguration extends ArrayCollection const ARCHIVE_ZIP = 'archive_zip'; const ARCHIVE_XML = 'archive_xml'; const ARCHIVE_VERSION_NUM = 'archive_version_num'; + const BACKUP_COMPLETED = 'backup_completed'; + const INSTALLED_LANGUAGES = 'installed_languages'; const CHANNEL_ONLINE = 'online'; const CHANNEL_LOCAL = 'local'; @@ -72,6 +74,11 @@ class UpgradeConfiguration extends ArrayCollection self::PS_AUTOUP_REGEN_EMAIL => true, self::PS_AUTOUP_BACKUP => true, self::PS_AUTOUP_KEEP_IMAGES => true, + self::BACKUP_COMPLETED => false, + ]; + + const CONFIGURATION_KEYS_ABOUT_SHOP = [ + self::INSTALLED_LANGUAGES, ]; const DEFAULT_CHANNEL = self::CHANNEL_ONLINE; @@ -147,6 +154,19 @@ public function isChannelOnline(): bool return $this->getChannelOrDefault() === UpgradeConfiguration::CHANNEL_ONLINE; } + public function isBackupCompleted(): bool + { + return $this->computeBooleanConfiguration(self::BACKUP_COMPLETED); + } + + /** + * @return string[] + */ + public function getInstalledLanguagesIsoCode(): array + { + return $this->get(self::INSTALLED_LANGUAGES); + } + /** * @return int Number of files to handle in a single call to avoid timeouts */ @@ -265,4 +285,15 @@ public function merge(array $array = []): void $this->set($key, $value); } } + + public function hasAllTheShopConfiguration(): bool + { + foreach (self::CONFIGURATION_KEYS_ABOUT_SHOP as $key) { + if ($this->get($key) === null) { + return false; + } + } + + return true; + } } diff --git a/classes/PrestashopConfiguration.php b/classes/PrestashopConfiguration.php index d3e87fcf4..7c22c200e 100644 --- a/classes/PrestashopConfiguration.php +++ b/classes/PrestashopConfiguration.php @@ -28,6 +28,7 @@ namespace PrestaShop\Module\AutoUpgrade; use Exception; +use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; class PrestashopConfiguration { @@ -116,4 +117,24 @@ public function findPrestaShopVersionInFile(string $content): ?string return null; } + + /** + * Rely on installed languages to merge translations files + * + * @return string[] + */ + public function getInstalledLanguages(): array + { + return array_map( + function ($v) { return $v['iso_code']; }, + \Language::getIsoIds(false) + ); + } + + public function fillInUpdateConfiguration(UpgradeConfiguration $upgradeConfiguration): void + { + $upgradeConfiguration->merge([ + UpgradeConfiguration::INSTALLED_LANGUAGES => $this->getInstalledLanguages(), + ]); + } } diff --git a/classes/State/AbstractState.php b/classes/State/AbstractState.php index 0e4bf03d4..a7a98ba34 100644 --- a/classes/State/AbstractState.php +++ b/classes/State/AbstractState.php @@ -30,6 +30,12 @@ use PrestaShop\Module\AutoUpgrade\Parameters\FileStorage; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; +/** + * The State is used to keep track of the remaining operations to do on the shop during a process. + * Its lifespan is strictly linked to a running process, it has no use outside it. + * + * @see PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration to prepare data that will be needed during an update. + */ abstract class AbstractState { /** @var bool */ diff --git a/classes/State/UpdateState.php b/classes/State/UpdateState.php index 83008409e..4042b408d 100644 --- a/classes/State/UpdateState.php +++ b/classes/State/UpdateState.php @@ -27,7 +27,9 @@ namespace PrestaShop\Module\AutoUpgrade\State; +use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; +use PrestaShop\Module\AutoUpgrade\Upgrader; class UpdateState extends AbstractState { @@ -53,11 +55,6 @@ class UpdateState extends AbstractState */ protected $installedLanguagesIso = []; - /** - * @var bool Marks the backup done during the update configuration - */ - protected $backupCompleted = false; - /** * @var bool Determining if all steps went totally successfully * @@ -70,18 +67,13 @@ protected function getFileNameForPersistentStorage(): string return UpgradeFileNames::STATE_UPDATE_FILENAME; } - public function initDefault(string $currentVersion, ?string $destinationVersion): void + public function initDefault(string $currentVersion, Upgrader $upgrader, UpgradeConfiguration $updateConfiguration): void { $this->disableSave = true; - // installedLanguagesIso is used to merge translations files - $installedLanguagesIso = array_map( - function ($v) { return $v['iso_code']; }, - \Language::getIsoIds(false) - ); - $this->setInstalledLanguagesIso($installedLanguagesIso); + $this->setInstalledLanguagesIso($updateConfiguration->getInstalledLanguagesIsoCode()); $this->setCurrentVersion($currentVersion); - $this->setDestinationVersion($destinationVersion); + $this->setDestinationVersion($upgrader->getDestinationVersion()); $this->disableSave = false; $this->save(); } @@ -129,19 +121,6 @@ public function setInstalledLanguagesIso(array $installedLanguagesIso): self return $this; } - public function isBackupCompleted(): bool - { - return $this->backupCompleted; - } - - public function setBackupCompleted(bool $completed): self - { - $this->backupCompleted = $completed; - $this->save(); - - return $this; - } - /** * @deprecated Unused on the UIs from v7 */ diff --git a/classes/Task/AbstractTask.php b/classes/Task/AbstractTask.php index 3d595bd05..fc3f29af7 100644 --- a/classes/Task/AbstractTask.php +++ b/classes/Task/AbstractTask.php @@ -206,11 +206,6 @@ protected function setupEnvironment(): void $archiveXml = $updateConfiguration->getLocalChannelXml(); $this->container->getFileLoader()->addXmlMd5File($this->container->getUpgrader()->getDestinationVersion(), $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $archiveXml); } - - if ($this::TASK_TYPE !== TaskType::TASK_TYPE_RESTORE && !$this->container->getUpdateState()->isInitialized()) { - $this->container->getUpdateState()->initDefault($this->container->getProperty(UpgradeContainer::PS_VERSION), $this->container->getUpgrader()->getDestinationVersion()); - $this->logger->debug($this->translator->trans('Successfully initialized update state.')); - } } abstract public function run(): int; diff --git a/classes/Task/Backup/BackupComplete.php b/classes/Task/Backup/BackupComplete.php index 36dd7bc65..eddb0dd9b 100644 --- a/classes/Task/Backup/BackupComplete.php +++ b/classes/Task/Backup/BackupComplete.php @@ -29,6 +29,7 @@ use Exception; use PrestaShop\Module\AutoUpgrade\Analytics; +use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\Task\TaskName; @@ -51,7 +52,10 @@ public function run(): int $this->next = TaskName::TASK_COMPLETE; $this->container->getFileStorage()->cleanAllBackupFiles(); - $this->container->getUpdateState()->setBackupCompleted(true); + $updateConfiguration = $this->container->getUpdateConfiguration(); + $updateConfiguration->merge([UpgradeConfiguration::BACKUP_COMPLETED => true]); + $this->container->getConfigurationStorage()->save($updateConfiguration); + $this->container->getAnalytics()->track('Backup Succeeded', Analytics::WITH_BACKUP_PROPERTIES); $this->logger->info($this->translator->trans('Backup completed successfully.')); diff --git a/classes/Task/Backup/BackupInitialization.php b/classes/Task/Backup/BackupInitialization.php index 5fab74d48..bbf0ec676 100644 --- a/classes/Task/Backup/BackupInitialization.php +++ b/classes/Task/Backup/BackupInitialization.php @@ -44,6 +44,7 @@ class BackupInitialization extends AbstractTask */ public function run(): int { + $this->container->getFileStorage()->cleanAllBackupFiles(); $this->container->getBackupState()->initDefault( $this->container->getProperty(UpgradeContainer::PS_VERSION) ); diff --git a/classes/Task/Restore/RestoreComplete.php b/classes/Task/Restore/RestoreComplete.php index e345512ce..941062791 100644 --- a/classes/Task/Restore/RestoreComplete.php +++ b/classes/Task/Restore/RestoreComplete.php @@ -46,7 +46,6 @@ public function run(): int $this->next = TaskName::TASK_COMPLETE; $this->container->getFileStorage()->cleanAllRestoreFiles(); - $this->container->getFileStorage()->cleanAllUpdateFiles(); $this->container->getAnalytics()->track('Restore Succeeded', Analytics::WITH_RESTORE_PROPERTIES); $this->container->getRestoreState()->setProgressPercentage( diff --git a/classes/Task/Restore/RestoreInitialization.php b/classes/Task/Restore/RestoreInitialization.php index d59de648b..8c747ec2d 100644 --- a/classes/Task/Restore/RestoreInitialization.php +++ b/classes/Task/Restore/RestoreInitialization.php @@ -49,6 +49,7 @@ class RestoreInitialization extends AbstractTask */ public function run(): int { + $this->container->getFileStorage()->cleanAllRestoreFiles(); $restoreConfiguration = $this->container->getRestoreConfiguration(); $state = $this->container->getRestoreState(); $state->initDefault($restoreConfiguration); diff --git a/classes/Task/Update/UpdateInitialization.php b/classes/Task/Update/UpdateInitialization.php index bc75744cc..9a115e39a 100644 --- a/classes/Task/Update/UpdateInitialization.php +++ b/classes/Task/Update/UpdateInitialization.php @@ -34,6 +34,7 @@ use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\Task\TaskName; use PrestaShop\Module\AutoUpgrade\Task\TaskType; +use PrestaShop\Module\AutoUpgrade\UpgradeContainer; /** * very first step of the upgrade process. The only thing done is the selection @@ -49,6 +50,13 @@ class UpdateInitialization extends AbstractTask public function run(): int { $this->logger->info($this->translator->trans('Starting update...')); + $this->container->getFileStorage()->cleanAllUpdateFiles(); + + $this->container->getUpdateState()->initDefault( + $this->container->getProperty(UpgradeContainer::PS_VERSION), + $this->container->getUpgrader(), + $this->container->getUpdateConfiguration() + ); $this->container->getUpdateState()->setProgressPercentage( $this->container->getCompletionCalculator()->getBasePercentageOfTask(self::class) ); diff --git a/classes/UpgradeContainer.php b/classes/UpgradeContainer.php index 17283b6d7..967426fdd 100644 --- a/classes/UpgradeContainer.php +++ b/classes/UpgradeContainer.php @@ -825,7 +825,6 @@ public function getUpgradeSelfCheck(): UpgradeSelfCheck $this->upgradeSelfCheck = new UpgradeSelfCheck( $this->getUpgrader(), - $this->getUpdateState(), $this->getUpdateConfiguration(), $this->getPrestaShopConfiguration(), $this->getTranslator(), @@ -833,7 +832,8 @@ public function getUpgradeSelfCheck(): UpgradeSelfCheck $this->getChecksumCompare(), $this->psRootDir, $this->adminDir, - $this->getProperty(UpgradeContainer::WORKSPACE_PATH) + $this->getProperty(UpgradeContainer::WORKSPACE_PATH), + $this->getProperty(UpgradeContainer::PS_VERSION) ); } diff --git a/classes/UpgradeSelfCheck.php b/classes/UpgradeSelfCheck.php index 0a3fb5d17..da55da2d1 100644 --- a/classes/UpgradeSelfCheck.php +++ b/classes/UpgradeSelfCheck.php @@ -35,7 +35,6 @@ use PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; use PrestaShop\Module\AutoUpgrade\Services\PhpVersionResolverService; -use PrestaShop\Module\AutoUpgrade\State\UpdateState; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator; use PrestaShop\Module\AutoUpgrade\Xml\ChecksumCompare; use Shop; @@ -66,8 +65,6 @@ class UpgradeSelfCheck private $maxExecutionTime; /** @var Upgrader */ private $upgrader; - /** @var UpdateState */ - private $state; /** * Path to the root folder of PS * @@ -86,6 +83,10 @@ class UpgradeSelfCheck * @var string */ private $autoUpgradePath; + /** @var string */ + private $currentVersion; + /** @var string */ + private $destinationVersion; /** @var PrestashopConfiguration */ private $prestashopConfiguration; /** @var UpgradeConfiguration */ @@ -124,7 +125,6 @@ class UpgradeSelfCheck public function __construct( Upgrader $upgrader, - UpdateState $state, UpgradeConfiguration $updateConfiguration, PrestashopConfiguration $prestashopConfiguration, Translator $translator, @@ -132,10 +132,10 @@ public function __construct( ChecksumCompare $checksumCompare, string $prodRootPath, string $adminPath, - string $autoUpgradePath + string $autoUpgradePath, + string $currentVersion ) { $this->upgrader = $upgrader; - $this->state = $state; $this->updateConfiguration = $updateConfiguration; $this->prestashopConfiguration = $prestashopConfiguration; $this->translator = $translator; @@ -144,6 +144,8 @@ public function __construct( $this->prodRootPath = $prodRootPath; $this->adminPath = $adminPath; $this->autoUpgradePath = $autoUpgradePath; + $this->currentVersion = $currentVersion; + $this->destinationVersion = $upgrader->getDestinationVersion(); } /** @@ -209,7 +211,7 @@ public function getWarnings(): array */ public function getRequirementWording(int $requirement, bool $isWebVersion = false): array { - $version = $this->state->getDestinationVersion(); + $version = $this->destinationVersion; $phpCompatibilityRange = $this->phpRequirementService->getPhpCompatibilityRange($version); switch ($requirement) { @@ -408,7 +410,7 @@ public function getRequirementWording(int $requirement, bool $isWebVersion = fal */ public function getCoreMissingFiles(): array { - $missingFiles = $this->checksumCompare->getTamperedFilesOnShop($this->state->getCurrentVersion()); + $missingFiles = $this->checksumCompare->getTamperedFilesOnShop($this->currentVersion); return array_merge($missingFiles['core']['missing'], $missingFiles['mail']['missing']); } @@ -418,7 +420,7 @@ public function getCoreMissingFiles(): array */ public function getCoreAlteredFiles(): array { - $alteredFiles = $this->checksumCompare->getTamperedFilesOnShop($this->state->getCurrentVersion()); + $alteredFiles = $this->checksumCompare->getTamperedFilesOnShop($this->currentVersion); return array_merge($alteredFiles['core']['altered'], $alteredFiles['mail']['altered']); } @@ -428,7 +430,7 @@ public function getCoreAlteredFiles(): array */ public function getThemeMissingFiles(): array { - $missingFiles = $this->checksumCompare->getTamperedFilesOnShop($this->state->getCurrentVersion()); + $missingFiles = $this->checksumCompare->getTamperedFilesOnShop($this->currentVersion); return $missingFiles['themes']['missing']; } @@ -438,7 +440,7 @@ public function getThemeMissingFiles(): array */ public function getThemeAlteredFiles(): array { - $alteredFiles = $this->checksumCompare->getTamperedFilesOnShop($this->state->getCurrentVersion()); + $alteredFiles = $this->checksumCompare->getTamperedFilesOnShop($this->currentVersion); return $alteredFiles['themes']['altered']; } @@ -580,7 +582,7 @@ public function isApacheModRewriteEnabled(): bool public function checkKeyGeneration(): bool { // Check if key is needed on the version we are upgrading to, if lower, not needed - if (version_compare($this->state->getDestinationVersion(), '8.1.0', '<')) { + if (version_compare($this->destinationVersion, '8.1.0', '<')) { return true; } @@ -661,7 +663,7 @@ public function isPhpFileUploadsConfigurationEnabled(): bool public function getPhpRequirementsState(): int { - $version = $this->state->getDestinationVersion(); + $version = $this->destinationVersion; return $this->phpRequirementService->getPhpRequirementsState(PHP_VERSION_ID, $version); } diff --git a/controllers/admin/AdminSelfUpgradeController.php b/controllers/admin/AdminSelfUpgradeController.php index 808c74d4e..4a0cc3987 100644 --- a/controllers/admin/AdminSelfUpgradeController.php +++ b/controllers/admin/AdminSelfUpgradeController.php @@ -297,17 +297,19 @@ public function init() empty($_REQUEST['params']) ? [] : $_REQUEST['params'] ); - if (!$this->ajax) { - // removing temporary files before init state to make sure state is already available - $this->upgradeContainer->getFileStorage()->cleanAllUpdateFiles(); - $this->upgradeContainer->getFileStorage()->cleanAllBackupFiles(); - $this->upgradeContainer->getFileStorage()->cleanAllRestoreFiles(); - } + $this->upgradeContainer->getFileStorage()->cleanAllUpdateFiles(); + $this->upgradeContainer->getFileStorage()->cleanAllBackupFiles(); + $this->upgradeContainer->getFileStorage()->cleanAllRestoreFiles(); + // TODO: Can be removed when the old UI is not needed anymore if (!$this->upgradeContainer->getUpdateState()->isInitialized()) { + $this->upgradeContainer->getPrestaShopConfiguration()->fillInUpdateConfiguration( + $this->upgradeContainer->getUpdateConfiguration() + ); $this->upgradeContainer->getUpdateState()->initDefault( $this->upgradeContainer->getProperty(UpgradeContainer::PS_VERSION), - $this->upgradeContainer->getUpgrader()->getDestinationVersion() + $this->upgradeContainer->getUpgrader(), + $this->upgradeContainer->getUpdateConfiguration() ); } diff --git a/controllers/admin/self-managed/HomePageController.php b/controllers/admin/self-managed/HomePageController.php index 343f1a24e..a9401e33d 100644 --- a/controllers/admin/self-managed/HomePageController.php +++ b/controllers/admin/self-managed/HomePageController.php @@ -28,6 +28,7 @@ namespace PrestaShop\Module\AutoUpgrade\Controller; use PrestaShop\Module\AutoUpgrade\AjaxResponseBuilder; +use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; use PrestaShop\Module\AutoUpgrade\Router\Routes; use Symfony\Component\HttpFoundation\JsonResponse; @@ -56,6 +57,8 @@ public function submit(): JsonResponse $routeChoice = $this->request->request->get(self::FORM_FIELDS['route_choice']); if ($routeChoice === self::FORM_OPTIONS['update_value']) { + $this->upgradeContainer->getFileStorage()->clean(UpgradeFileNames::UPDATE_CONFIG_FILENAME); + return AjaxResponseBuilder::nextRouteResponse(Routes::UPDATE_PAGE_VERSION_CHOICE); } @@ -64,6 +67,8 @@ public function submit(): JsonResponse return AjaxResponseBuilder::errorResponse('You can\'t access this route because you have no backups.', 401); } + $this->upgradeContainer->getFileStorage()->clean(UpgradeFileNames::RESTORE_CONFIG_FILENAME); + return AjaxResponseBuilder::nextRouteResponse(Routes::RESTORE_PAGE_BACKUP_SELECTION); } diff --git a/controllers/admin/self-managed/UpdatePageBackupOptionsController.php b/controllers/admin/self-managed/UpdatePageBackupOptionsController.php index a4d53c3b1..6da50506b 100644 --- a/controllers/admin/self-managed/UpdatePageBackupOptionsController.php +++ b/controllers/admin/self-managed/UpdatePageBackupOptionsController.php @@ -68,7 +68,7 @@ public function submitBackup(): JsonResponse public function submitUpdate(): JsonResponse { return $this->displayDialog('dialog-update', [ - 'backup_completed' => $this->upgradeContainer->getUpdateState()->isBackupCompleted(), + 'backup_completed' => $this->upgradeContainer->getUpdateConfiguration()->isBackupCompleted(), 'dialogId' => 'dialog-confirm-update', 'form_route_to_confirm' => Routes::UPDATE_STEP_BACKUP_CONFIRM_UPDATE, @@ -124,7 +124,7 @@ protected function getParams(): array return array_merge( $updateSteps->getStepParams($this::CURRENT_STEP), [ - 'backup_completed' => $this->upgradeContainer->getUpdateState()->isBackupCompleted(), + 'backup_completed' => $this->upgradeContainer->getUpdateConfiguration()->isBackupCompleted(), 'download_path' => $logsPath, 'filename' => basename($logsPath), diff --git a/controllers/admin/self-managed/UpdatePageVersionChoiceController.php b/controllers/admin/self-managed/UpdatePageVersionChoiceController.php index 37a838872..fd9613431 100644 --- a/controllers/admin/self-managed/UpdatePageVersionChoiceController.php +++ b/controllers/admin/self-managed/UpdatePageVersionChoiceController.php @@ -193,17 +193,19 @@ public function save(): JsonResponse if ($isLocal) { $file = $requestConfig[UpgradeConfiguration::ARCHIVE_ZIP]; $fullFilePath = $this->upgradeContainer->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $file; - $requestConfig['archive_version_num'] = $this->upgradeContainer->getPrestashopVersionService()->extractPrestashopVersionFromZip($fullFilePath); + $requestConfig[UpgradeConfiguration::ARCHIVE_VERSION_NUM] = $this->upgradeContainer->getPrestashopVersionService()->extractPrestashopVersionFromZip($fullFilePath); } $configurationStorage = $this->upgradeContainer->getConfigurationStorage(); - $config = $this->upgradeContainer->getUpdateConfiguration(); - $config->merge($requestConfig); + $updateConfiguration = $this->upgradeContainer->getUpdateConfiguration(); + $updateConfiguration->merge($requestConfig); - $configurationStorage->save($config); - $state = $this->upgradeContainer->getUpdateState()->setDestinationVersion($this->upgradeContainer->getUpgrader()->getDestinationVersion()); - $state->save(); + if (!$updateConfiguration->hasAllTheShopConfiguration()) { + $this->upgradeContainer->getPrestaShopConfiguration()->fillInUpdateConfiguration($updateConfiguration); + } + + $configurationStorage->save($updateConfiguration); if ($channel !== null) { $params[$channel . '_requirements'] = $this->getRequirements(); diff --git a/tests/unit/Parameters/UpgradeConfigurationTest.php b/tests/unit/Parameters/UpgradeConfigurationTest.php new file mode 100644 index 000000000..44198be03 --- /dev/null +++ b/tests/unit/Parameters/UpgradeConfigurationTest.php @@ -0,0 +1,48 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ + +namespace Parameters; + +use PHPUnit\Framework\TestCase; +use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; + +class UpgradeConfigurationTest extends TestCase +{ + public function testUpdateConfigurationConfigIsFilledWithPrestaShopOne(): void + { + $updateConfiguration = new UpgradeConfiguration(); + + $this->assertFalse($updateConfiguration->hasAllTheShopConfiguration()); + + // We can't use the class PrestaShopConfiguration directly because of its reliance on the Core. + // Reproduce its alterations below: + $updateConfiguration->merge([ + UpgradeConfiguration::INSTALLED_LANGUAGES => ['fr', 'de', 'jp'], + ]); + + $this->assertTrue($updateConfiguration->hasAllTheShopConfiguration()); + } +} diff --git a/tests/unit/State/UpdateStateTest.php b/tests/unit/State/UpdateStateTest.php index 226c24a6f..ee97ac084 100644 --- a/tests/unit/State/UpdateStateTest.php +++ b/tests/unit/State/UpdateStateTest.php @@ -27,10 +27,9 @@ public function testExportOfData(): void 'currentVersion' => '1.7.8.6', 'destinationVersion' => '9.0.0', 'installedLanguagesIso' => [], - 'backupCompleted' => false, 'warning_exists' => false, - 'progressPercentage' => '20', + 'progressPercentage' => 20, ]; $this->assertEquals($expected, $this->state->export()); @@ -95,7 +94,6 @@ public function testLoadState(): void $this->assertEquals('1.6.1.24', $this->state->getCurrentVersion()); $this->assertEquals('9.2.3', $this->state->getDestinationVersion()); - $this->assertTrue($this->state->isBackupCompleted()); $this->assertEquals(['fr', 'de'], $this->state->getInstalledLanguagesIso()); }