diff --git a/php/public/index.php b/php/public/index.php index 5d706c2d..eb2a7878 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -103,6 +103,7 @@ $app->post('/api/docker/backup-check-repair', AIO\Controller\DockerController::c $app->post('/api/docker/backup-test', AIO\Controller\DockerController::class . ':StartBackupContainerTest'); $app->post('/api/docker/restore', AIO\Controller\DockerController::class . ':StartBackupContainerRestore'); $app->post('/api/docker/stop', AIO\Controller\DockerController::class . ':StopContainer'); +$app->post('/api/docker/backup-reset-location', AIO\Controller\DockerController::class . ':DeleteBorgBackupConfig'); $app->post('/api/docker/prune', AIO\Controller\DockerController::class . ':SystemPrune'); $app->get('/api/docker/logs', AIO\Controller\DockerController::class . ':GetLogs'); $app->post('/api/auth/login', AIO\Controller\LoginController::class . ':TryLogin'); diff --git a/php/src/Controller/ConfigurationController.php b/php/src/Controller/ConfigurationController.php index 4dbe3ae2..8e351827 100644 --- a/php/src/Controller/ConfigurationController.php +++ b/php/src/Controller/ConfigurationController.php @@ -3,16 +3,14 @@ declare(strict_types=1); namespace AIO\Controller; -use AIO\ContainerDefinitionFetcher; use AIO\Data\ConfigurationManager; use AIO\Data\InvalidSettingConfigurationException; -use AIO\Docker\DockerActionManager; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; readonly class ConfigurationController { public function __construct( - private ConfigurationManager $configurationManager + private ConfigurationManager $configurationManager, ) { } @@ -132,10 +130,6 @@ readonly class ConfigurationController { $this->configurationManager->collaboraAdditionalOptions = $additionalCollaboraOptions; } - if (isset($request->getParsedBody()['delete_borg_backup_location_vars'])) { - $this->configurationManager->deleteBorgBackupLocationItems(); - } - return $response->withStatus(201)->withHeader('Location', '.'); } catch (InvalidSettingConfigurationException $ex) { $response->getBody()->write($ex->getMessage()); diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 835ed6d5..66e8a3e2 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -328,6 +328,11 @@ readonly class DockerController { return $nonbufResp; } + public function DeleteBorgBackupConfig(Request $request, Response $response, array $args) : Response { + $this->dockerActionManager->deleteBorgBackupConfig(); + return $response->withStatus(201)->withHeader('Location', '.'); + } + public function SystemPrune(Request $request, Response $response, array $args) : Response { // Get streaming response start and closure $nonbufResp = $this->startStreamingResponse($response); diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 940814fe..ca6a4d72 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -145,6 +145,27 @@ readonly class DockerActionManager { } } + public function deleteBorgBackupConfig(): void { + // Delete the borgbackup container + $id = 'nextcloud-aio-borgbackup'; + $borgbackupContainer = $this->containerDefinitionFetcher->GetContainerById($id); + $this->DeleteContainer($borgbackupContainer); + + // Delete the borg cache volume + $url = $this->BuildApiUrl('volumes/nextcloud_aio_backup_cache'); + try { + $this->guzzleClient->delete($url); + error_log('nextcloud_aio_backup_cache volume deleted successfully.'); + } catch (RequestException $e) { + if ($e->getCode() !== 404) { + error_log('Could not delete nextcloud_aio_backup_cache volume: ' . $e->getMessage()); + } + } + + // Clear the configuration variables and files + $this->configurationManager->deleteBorgBackupLocationItems(); + } + public function GetLogs(string $id, string $since = ''): string { $url = $this->BuildApiUrl( sprintf( diff --git a/php/templates/containers.twig b/php/templates/containers.twig index adfe3161..dc71fd02 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -566,8 +566,7 @@ {% endif %} is wrong or if you want to reset the backup location due to other reasons, you can do so by clicking on the button below.

-
- +