diff --git a/classes/Parameters/UpgradeFileNames.php b/classes/Parameters/UpgradeFileNames.php index d249e99c50..91a1f72fbd 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 ea99a21a7b..481a8ab495 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 0a7a68d73d..38d2037703 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 2439f7bf77..67977dbc9b 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 5ab43797cf..fcb6f625ca 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 f1697af987..81d54ad7a7 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('/`(?