diff --git a/classes/Parameters/UpgradeFileNames.php b/classes/Parameters/UpgradeFileNames.php
index d249e99c5..91a1f72fb 100644
--- a/classes/Parameters/UpgradeFileNames.php
+++ b/classes/Parameters/UpgradeFileNames.php
@@ -50,15 +50,6 @@ class UpgradeFileNames
*/
const CONFIG_FILENAME = 'config.var';
- /**
- * during upgradeFiles process,
- * this files contains the list of queries left to upgrade in a serialized array.
- * (this file is deleted in init() method if you reload the page).
- *
- * @var string
- */
- const QUERIES_TO_UPGRADE_LIST = 'queriesToUpgrade.list';
-
/**
* during upgradeFiles process,
* this files contains the list of files left to upgrade in a serialized array.
@@ -151,7 +142,6 @@ class UpgradeFileNames
*/
public static $update_tmp_files = [
'STATE_FILENAME' => self::STATE_UPDATE_FILENAME,
- 'QUERIES_TO_UPGRADE_LIST' => self::QUERIES_TO_UPGRADE_LIST, // used ?
'FILES_TO_UPGRADE_LIST' => self::FILES_TO_UPGRADE_LIST,
'DB_TABLES_TO_CLEAN_LIST' => self::DB_TABLES_TO_CLEAN_LIST,
'FILES_TO_REMOVE_LIST' => self::FILES_TO_REMOVE_LIST,
diff --git a/classes/State/BackupState.php b/classes/State/BackupState.php
index ea99a21a7..481a8ab49 100644
--- a/classes/State/BackupState.php
+++ b/classes/State/BackupState.php
@@ -71,6 +71,7 @@ protected function getFileNameForPersistentStorage(): string
public function initDefault(string $currentVersion): void
{
+ $this->disableSave = true;
$rand = dechex(mt_rand(0, min(0xffffffff, mt_getrandmax())));
$date = date('Ymd-His');
$backupName = 'V' . $currentVersion . '_' . $date . '-' . $rand;
@@ -79,6 +80,9 @@ public function initDefault(string $currentVersion): void
$this->setBackupTable(null);
$this->setBackupLoopLimit(null);
$this->setDbStep(0);
+
+ $this->disableSave = false;
+ $this->save();
}
public function getBackupName(): string
diff --git a/classes/Task/AbstractTask.php b/classes/Task/AbstractTask.php
index 0a7a68d73..38d203770 100644
--- a/classes/Task/AbstractTask.php
+++ b/classes/Task/AbstractTask.php
@@ -209,11 +209,6 @@ protected function setupEnvironment(): void
$this->container->getUpdateState()->initDefault($this->container->getProperty(UpgradeContainer::PS_VERSION), $this->container->getUpgrader()->getDestinationVersion());
$this->logger->debug($this->translator->trans('Successfully initialized update state.'));
}
-
- if ($this::TASK_TYPE === TaskType::TASK_TYPE_BACKUP && !$this->container->getBackupState()->isInitialized()) {
- $this->container->getBackupState()->initDefault($this->container->getProperty(UpgradeContainer::PS_VERSION));
- $this->logger->debug($this->translator->trans('Successfully initialized backup state.'));
- }
}
abstract public function run(): int;
diff --git a/classes/Task/Backup/BackupFiles.php b/classes/Task/Backup/BackupFiles.php
index 2439f7bf7..67977dbc9 100644
--- a/classes/Task/Backup/BackupFiles.php
+++ b/classes/Task/Backup/BackupFiles.php
@@ -45,8 +45,9 @@ class BackupFiles extends AbstractTask
*/
public function run(): int
{
+ $state = $this->container->getBackupState();
$this->stepDone = false;
- $backupFilesFilename = $this->container->getBackupState()->getBackupFilesFilename();
+ $backupFilesFilename = $state->getBackupFilesFilename();
if (empty($backupFilesFilename)) {
$this->next = TaskName::TASK_ERROR;
$this->setErrorFlag();
@@ -57,7 +58,7 @@ public function run(): int
}
if (!$this->container->getFileConfigurationStorage()->exists(UpgradeFileNames::FILES_TO_BACKUP_LIST)) {
- $this->container->getBackupState()->setProgressPercentage(
+ $state->setProgressPercentage(
$this->container->getCompletionCalculator()->getBasePercentageOfTask(self::class)
);
@@ -93,7 +94,7 @@ public function run(): int
return ExitCode::FAIL;
}
$this->container->getFileConfigurationStorage()->save($backlog->dump(), UpgradeFileNames::FILES_TO_BACKUP_LIST);
- $this->container->getBackupState()->setProgressPercentage(
+ $state->setProgressPercentage(
$this->container->getCompletionCalculator()->computePercentage($backlog, self::class, BackupDatabase::class)
);
} else {
diff --git a/classes/Task/Restore/Restore.php b/classes/Task/Restore/Restore.php
index 5ab43797c..fcb6f625c 100644
--- a/classes/Task/Restore/Restore.php
+++ b/classes/Task/Restore/Restore.php
@@ -49,14 +49,16 @@ class Restore extends AbstractTask
*/
public function run(): int
{
- $this->container->getRestoreState()->setProgressPercentage(
+ $state = $this->container->getRestoreState();
+
+ $state->setProgressPercentage(
$this->container->getCompletionCalculator()->getBasePercentageOfTask(self::class)
);
// 1st, need to analyse what was wrong.
- $restoreName = $this->container->getRestoreState()->getRestoreName();
- $this->container->getRestoreState()->setRestoreFilesFilename($restoreName);
- $restoreDbFilenames = $this->container->getRestoreState()->getRestoreDbFilenames();
+ $restoreName = $state->getRestoreName();
+ $state->setRestoreFilesFilename($restoreName);
+ $restoreDbFilenames = $state->getRestoreDbFilenames();
if (empty($restoreName)) {
$this->next = TaskName::TASK_RESTORE_EMPTY;
@@ -68,14 +70,14 @@ public function run(): int
// find backup filenames, and be sure they exists
foreach ($files as $file) {
if (preg_match('#' . preg_quote(BackupFinder::BACKUP_ZIP_NAME_PREFIX . $restoreName) . '#', $file)) {
- $this->container->getRestoreState()->setRestoreFilesFilename($file);
+ $state->setRestoreFilesFilename($file);
break;
}
}
- if (!is_file($this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $this->container->getRestoreState()->getRestoreFilesFilename())) {
+ if (!is_file($this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $state->getRestoreFilesFilename())) {
$this->next = TaskName::TASK_ERROR;
$this->setErrorFlag();
- $this->logger->error($this->translator->trans('File %s is missing: unable to restore files. Operation aborted.', [$this->container->getRestoreState()->getRestoreFilesFilename()]));
+ $this->logger->error($this->translator->trans('File %s is missing: unable to restore files. Operation aborted.', [$state->getRestoreFilesFilename()]));
return ExitCode::FAIL;
}
@@ -88,7 +90,7 @@ public function run(): int
// order files is important !
sort($restoreDbFilenames);
- $this->container->getRestoreState()->setRestoreDbFilenames($restoreDbFilenames);
+ $state->setRestoreDbFilenames($restoreDbFilenames);
if (count($restoreDbFilenames) == 0) {
$this->next = TaskName::TASK_ERROR;
$this->setErrorFlag();
diff --git a/classes/Task/Restore/RestoreDatabase.php b/classes/Task/Restore/RestoreDatabase.php
index f1697af98..81d54ad7a 100644
--- a/classes/Task/Restore/RestoreDatabase.php
+++ b/classes/Task/Restore/RestoreDatabase.php
@@ -50,7 +50,8 @@ class RestoreDatabase extends AbstractTask
*/
public function run(): int
{
- $this->container->getRestoreState()->setProgressPercentage(
+ $state = $this->container->getRestoreState();
+ $state->setProgressPercentage(
$this->container->getCompletionCalculator()->getBasePercentageOfTask(self::class)
);
@@ -70,10 +71,10 @@ public function run(): int
}
// deal with the next files stored in restoreDbFilenames
- $restoreDbFilenames = $this->container->getRestoreState()->getRestoreDbFilenames();
+ $restoreDbFilenames = $state->getRestoreDbFilenames();
if ((!isset($backlog) || !$backlog->getRemainingTotal()) && count($restoreDbFilenames) > 0) {
$currentDbFilename = array_shift($restoreDbFilenames);
- $this->container->getRestoreState()->setRestoreDbFilenames($restoreDbFilenames);
+ $state->setRestoreDbFilenames($restoreDbFilenames);
if (!preg_match('#' . BackupFinder::BACKUP_DB_FOLDER_NAME_PREFIX . '([0-9]{6})_#', $currentDbFilename, $match)) {
$this->next = TaskName::TASK_ERROR;
$this->setErrorFlag();
@@ -81,8 +82,8 @@ public function run(): int
return ExitCode::FAIL;
}
- $this->container->getRestoreState()->setDbStep((int) $match[1]);
- $backupdb_path = $this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $this->container->getRestoreState()->getRestoreName();
+ $state->setDbStep((int) $match[1]);
+ $backupdb_path = $this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $state->getRestoreName();
$dot_pos = strrpos($currentDbFilename, '.');
$fileext = substr($currentDbFilename, $dot_pos + 1);
@@ -140,7 +141,7 @@ public function run(): int
unset($content);
// Get tables before backup
- if ($this->container->getRestoreState()->getDbStep() == '1') {
+ if ($state->getDbStep() == '1') {
$tables_after_restore = [];
foreach ($listQuery as $q) {
if (preg_match('/`(?
' . _DB_PREFIX_ . '[a-zA-Z0-9_-]+)`/', $q, $matches)) {
@@ -173,17 +174,17 @@ public function run(): int
unlink($this->container->getProperty(UpgradeContainer::WORKSPACE_PATH) . DIRECTORY_SEPARATOR . UpgradeFileNames::QUERIES_TO_RESTORE_LIST);
}
- $restoreDbFilenamesCount = count($this->container->getRestoreState()->getRestoreDbFilenames());
+ $restoreDbFilenamesCount = count($state->getRestoreDbFilenames());
if ($restoreDbFilenamesCount) {
$this->logger->info($this->translator->trans(
'Database restoration file %filename% done. %filescount% file(s) left...',
[
- '%filename%' => $this->container->getRestoreState()->getDbStep(),
+ '%filename%' => $state->getDbStep(),
'%filescount%' => $restoreDbFilenamesCount,
]
));
} else {
- $this->logger->info($this->translator->trans('Database restoration file %1$s done.', [$this->container->getRestoreState()->getDbStep()]));
+ $this->logger->info($this->translator->trans('Database restoration file %1$s done.', [$state->getDbStep()]));
}
$this->stepDone = true;
@@ -230,7 +231,7 @@ public function run(): int
'%numberqueries% queries left for file %filename%...',
[
'%numberqueries%' => $queries_left,
- '%filename%' => $this->container->getRestoreState()->getDbStep(),
+ '%filename%' => $state->getDbStep(),
]
));
} else {
diff --git a/classes/Task/Restore/RestoreFiles.php b/classes/Task/Restore/RestoreFiles.php
index e03ce29b4..4bc7e997d 100644
--- a/classes/Task/Restore/RestoreFiles.php
+++ b/classes/Task/Restore/RestoreFiles.php
@@ -48,7 +48,8 @@ class RestoreFiles extends AbstractTask
*/
public function run(): int
{
- $this->container->getRestoreState()->setProgressPercentage(
+ $state = $this->container->getRestoreState();
+ $state->setProgressPercentage(
$this->container->getCompletionCalculator()->getBasePercentageOfTask(self::class)
);
@@ -57,7 +58,7 @@ public function run(): int
if (!file_exists($this->container->getProperty(UpgradeContainer::WORKSPACE_PATH) . DIRECTORY_SEPARATOR . UpgradeFileNames::FILES_FROM_ARCHIVE_LIST)
|| !file_exists($this->container->getProperty(UpgradeContainer::WORKSPACE_PATH) . DIRECTORY_SEPARATOR . UpgradeFileNames::FILES_TO_REMOVE_LIST)) {
// cleanup current PS tree
- $fromArchive = $this->container->getZipAction()->listContent($this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $this->container->getRestoreState()->getRestoreFilesFilename());
+ $fromArchive = $this->container->getZipAction()->listContent($this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $state->getRestoreFilesFilename());
foreach ($fromArchive as $k => $v) {
$fromArchive[DIRECTORY_SEPARATOR . $v] = DIRECTORY_SEPARATOR . $v;
}
@@ -98,7 +99,7 @@ public function run(): int
}
if (!empty($fromArchive)) {
- $filepath = $this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $this->container->getRestoreState()->getRestoreFilesFilename();
+ $filepath = $this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $state->getRestoreFilesFilename();
$destExtract = $this->container->getProperty(UpgradeContainer::PS_ROOT_PATH);
$res = $this->container->getZipAction()->extract($filepath, $destExtract);
diff --git a/classes/Task/Update/UpdateComplete.php b/classes/Task/Update/UpdateComplete.php
index 084f3681e..928691bf7 100644
--- a/classes/Task/Update/UpdateComplete.php
+++ b/classes/Task/Update/UpdateComplete.php
@@ -48,13 +48,14 @@ class UpdateComplete extends AbstractTask
*/
public function run(): int
{
- $this->container->getUpdateState()->setProgressPercentage(
+ $state = $this->container->getUpdateState();
+ $state->setProgressPercentage(
$this->container->getCompletionCalculator()->getBasePercentageOfTask(self::class)
);
- $destinationVersion = $this->container->getUpdateState()->getDestinationVersion();
+ $destinationVersion = $state->getDestinationVersion();
- $this->logger->info($this->container->getUpdateState()->getWarningExists() ?
+ $this->logger->info($state->getWarningExists() ?
$this->translator->trans('Shop updated to %s, but some warnings have been found.', [$destinationVersion]) :
$this->translator->trans('Shop updated to %s. Congratulations! You can now reactivate your shop.', [$destinationVersion])
);
diff --git a/classes/Task/Update/UpdateDatabase.php b/classes/Task/Update/UpdateDatabase.php
index dc6c4cf2c..ad5e5e87c 100644
--- a/classes/Task/Update/UpdateDatabase.php
+++ b/classes/Task/Update/UpdateDatabase.php
@@ -50,10 +50,11 @@ class UpdateDatabase extends AbstractTask
public function run(): int
{
+ $state = $this->container->getUpdateState();
try {
if (!$this->container->getFileConfigurationStorage()->exists(UpgradeFileNames::SQL_TO_EXECUTE_LIST)) {
$this->warmUp();
- $currentVersion = $this->container->getUpdateState()->getCurrentVersion();
+ $currentVersion = $state->getCurrentVersion();
$sqlContentList = $this->getCoreUpgrader()->getSqlContentList($currentVersion);
$backlog = new Backlog(array_reverse($sqlContentList), count($sqlContentList));
} else {
@@ -66,7 +67,7 @@ public function run(): int
$this->updateDatabase($backlog);
- $this->container->getUpdateState()->setProgressPercentage(
+ $state->setProgressPercentage(
$this->container->getCompletionCalculator()->computePercentage($backlog, self::class, UpdateModules::class)
);
@@ -101,9 +102,9 @@ public function getCoreUpgrader(): CoreUpgrader
return $this->coreUpgrader;
}
- if (version_compare($this->container->getUpdateState()->getDestinationVersion(), '8', '<')) {
+ if (version_compare($state->getDestinationVersion(), '8', '<')) {
$this->coreUpgrader = new CoreUpgrader17($this->container, $this->logger);
- } elseif (version_compare($this->container->getUpdateState()->getDestinationVersion(), '8.1', '<')) {
+ } elseif (version_compare($state->getDestinationVersion(), '8.1', '<')) {
$this->coreUpgrader = new CoreUpgrader80($this->container, $this->logger);
} else {
$this->coreUpgrader = new CoreUpgrader81($this->container, $this->logger);
@@ -134,7 +135,7 @@ protected function warmUp(): int
{
$this->logger->info($this->container->getTranslator()->trans('Updating database data and structure'));
- $this->container->getUpdateState()->setProgressPercentage(
+ $state->setProgressPercentage(
$this->container->getCompletionCalculator()->getBasePercentageOfTask(self::class)
);
@@ -164,8 +165,8 @@ protected function warmUp(): int
*/
protected function checkVersionIsNewer(): void
{
- $currentVersion = VersionUtils::normalizePrestaShopVersion($this->container->getUpdateState()->getCurrentVersion());
- $destinationVersion = VersionUtils::normalizePrestaShopVersion($this->container->getUpdateState()->getDestinationVersion());
+ $currentVersion = VersionUtils::normalizePrestaShopVersion($state->getCurrentVersion());
+ $destinationVersion = VersionUtils::normalizePrestaShopVersion($state->getDestinationVersion());
$versionCompare = version_compare($destinationVersion, $currentVersion);
diff --git a/classes/Task/Update/UpdateFiles.php b/classes/Task/Update/UpdateFiles.php
index f0ac95435..72eb66517 100644
--- a/classes/Task/Update/UpdateFiles.php
+++ b/classes/Task/Update/UpdateFiles.php
@@ -197,7 +197,8 @@ public function upgradeThisFile($orig): bool
*/
protected function warmUp(): int
{
- $this->container->getUpdateState()->setProgressPercentage(
+ $state = $this->container->getUpdateState();
+ $state->setProgressPercentage(
$this->container->getCompletionCalculator()->getBasePercentageOfTask(self::class)
);
@@ -224,8 +225,8 @@ protected function warmUp(): int
rename($newReleasePath . DIRECTORY_SEPARATOR . 'install-dev', $newReleasePath . DIRECTORY_SEPARATOR . 'install');
}
- $destinationVersion = $this->container->getUpdateState()->getDestinationVersion();
- $originVersion = $this->container->getUpdateState()->getCurrentVersion();
+ $destinationVersion = $state->getDestinationVersion();
+ $originVersion = $state->getCurrentVersion();
$this->logger->debug($this->translator->trans('Generate diff file list between %s and %s.', [$originVersion, $destinationVersion]));
$diffFileList = $this->container->getChecksumCompare()->getFilesDiffBetweenVersions($originVersion, $destinationVersion);
if (!is_array($diffFileList)) {
diff --git a/classes/UpgradeContainer.php b/classes/UpgradeContainer.php
index aad620426..6d5ae4dd7 100644
--- a/classes/UpgradeContainer.php
+++ b/classes/UpgradeContainer.php
@@ -676,6 +676,8 @@ public function getUpdateState(): UpdateState
/**
* @param TaskType::TASK_TYPE_* $taskType
+ *
+ * @throws InvalidArgumentException
*/
public function getStateFromTaskType($taskType): AbstractState
{