From 6576d3c1e9e8e4d0c118dc3388ab8415152b7690 Mon Sep 17 00:00:00 2001 From: Pablo Zmdl Date: Mon, 19 Jan 2026 12:58:50 +0100 Subject: [PATCH] Make `backupMode` an attribute Signed-off-by: Pablo Zmdl --- php/public/index.php | 2 +- php/src/Controller/DockerController.php | 14 +++++++------- php/src/Data/ConfigurationManager.php | 20 +++++--------------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/php/public/index.php b/php/public/index.php index a0b45675..6abe1989 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -104,7 +104,7 @@ $app->get('/containers', function (Request $request, Response $response, array $ 'is_backup_container_running' => $dockerActionManager->isBackupContainerRunning(), 'backup_exit_code' => $dockerActionManager->GetBackupcontainerExitCode(), 'is_instance_restore_attempt' => $configurationManager->isInstanceRestoreAttempt(), - 'borg_backup_mode' => $configurationManager->GetBackupMode(), + 'borg_backup_mode' => $configurationManager->backupMode, 'was_start_button_clicked' => $configurationManager->wasStartButtonClicked, 'has_update_available' => $dockerActionManager->isAnyUpdateAvailable(), 'last_backup_time' => $configurationManager->GetLastBackupTime(), diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 0ee4e522..566f430a 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -89,7 +89,7 @@ readonly class DockerController { } public function startBackup(bool $forceStopNextcloud = false) : void { - $this->configurationManager->SetBackupMode('backup'); + $this->configurationManager->backupMode = 'backup'; $id = self::TOP_CONTAINER; $this->PerformRecursiveContainerStop($id, $forceStopNextcloud); @@ -109,21 +109,21 @@ readonly class DockerController { } public function checkBackup() : void { - $this->configurationManager->SetBackupMode('check'); + $this->configurationManager->backupMode = 'check'; $id = 'nextcloud-aio-borgbackup'; $this->PerformRecursiveContainerStart($id); } private function listBackup() : void { - $this->configurationManager->SetBackupMode('list'); + $this->configurationManager->backupMode = 'list'; $id = 'nextcloud-aio-borgbackup'; $this->PerformRecursiveContainerStart($id); } public function StartBackupContainerRestore(Request $request, Response $response, array $args) : Response { - $this->configurationManager->SetBackupMode('restore'); + $this->configurationManager->backupMode = 'restore'; $this->configurationManager->selectedRestoreTime = $request->getParsedBody()['selected_restore_time'] ?? ''; $this->configurationManager->restoreExcludePreviews = isset($request->getParsedBody()['restore-exclude-previews']); @@ -138,22 +138,22 @@ readonly class DockerController { } public function StartBackupContainerCheckRepair(Request $request, Response $response, array $args) : Response { - $this->configurationManager->SetBackupMode('check-repair'); + $this->configurationManager->backupMode = 'check-repair'; $id = 'nextcloud-aio-borgbackup'; $this->PerformRecursiveContainerStart($id); // Restore to backup check which is needed to make the UI logic work correctly - $this->configurationManager->SetBackupMode('check'); + $this->configurationManager->backupMode = 'check'; return $response->withStatus(201)->withHeader('Location', '.'); } public function StartBackupContainerTest(Request $request, Response $response, array $args) : Response { - $this->configurationManager->SetBackupMode('test'); $config = $this->configurationManager->GetConfig(); $config['instance_restore_attempt'] = 0; $this->configurationManager->WriteConfig($config); + $this->configurationManager->backupMode = 'test'; $id = self::TOP_CONTAINER; $this->PerformRecursiveContainerStop($id); diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index a6dd196a..e21984b6 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -38,6 +38,11 @@ class ConfigurationManager set { $this->set('selected-restore-time', $value); } } + public string $backupMode { + get => $this->get('backup-mode', ''); + set { $this->set('backup-mode', $value); } + } + public string $AIO_URL { get => $this->get('AIO_URL', ''); set { $this->set('AIO_URL', $value); } @@ -452,21 +457,6 @@ class ConfigurationManager return 'dc=' . implode(',dc=', explode('.', $domain)); } - public function GetBackupMode() : string { - $config = $this->GetConfig(); - if(!isset($config['backup-mode'])) { - $config['backup-mode'] = ''; - } - - return $config['backup-mode']; - } - - public function SetBackupMode(string $mode) : void { - $config = $this->GetConfig(); - $config['backup-mode'] = $mode; - $this->WriteConfig($config); - } - /** * @throws InvalidSettingConfigurationException */