From 099298d6955764384d871aed82e25356572bcf72 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Mar 2026 15:39:34 +0000 Subject: [PATCH] Rebase onto base branch, use startStreamingResponse from base Co-authored-by: szaimen <42591237+szaimen@users.noreply.github.com> --- php/src/Controller/DockerController.php | 177 ++++++++++++++++-------- php/templates/containers.twig | 37 ++--- 2 files changed, 141 insertions(+), 73 deletions(-) diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 42a3ae2e..be182c28 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -87,43 +87,64 @@ readonly class DockerController { } public function StartBackupContainerBackup(Request $request, Response $response, array $args) : Response { + // Get streaming response start and closure + $nonbufResp = $this->startStreamingResponse($response); + $addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp); + $forceStopNextcloud = true; - $this->startBackup($forceStopNextcloud); - return $response->withStatus(201)->withHeader('Location', '.'); + $this->startBackup($forceStopNextcloud, $addToStreamingResponseBody); + + // End streaming response + $this->finalizeStreamingResponse($nonbufResp); + return $nonbufResp; } - public function startBackup(bool $forceStopNextcloud = false) : void { + public function startBackup(bool $forceStopNextcloud = false, ?\Closure $addToStreamingResponseBody = null) : void { $this->configurationManager->backupMode = 'backup'; $id = self::TOP_CONTAINER; - $this->PerformRecursiveContainerStop($id, $forceStopNextcloud); + $this->PerformRecursiveContainerStop($id, $forceStopNextcloud, $addToStreamingResponseBody); $id = 'nextcloud-aio-borgbackup'; - $this->PerformRecursiveContainerStart($id); + $this->PerformRecursiveContainerStart($id, true, $addToStreamingResponseBody); } public function StartBackupContainerCheck(Request $request, Response $response, array $args) : Response { - $this->checkBackup(); - return $response->withStatus(201)->withHeader('Location', '.'); + // Get streaming response start and closure + $nonbufResp = $this->startStreamingResponse($response); + $addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp); + + $this->checkBackup($addToStreamingResponseBody); + + // End streaming response + $this->finalizeStreamingResponse($nonbufResp); + return $nonbufResp; } public function StartBackupContainerList(Request $request, Response $response, array $args) : Response { - $this->listBackup(); - return $response->withStatus(201)->withHeader('Location', '.'); + // Get streaming response start and closure + $nonbufResp = $this->startStreamingResponse($response); + $addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp); + + $this->listBackup($addToStreamingResponseBody); + + // End streaming response + $this->finalizeStreamingResponse($nonbufResp); + return $nonbufResp; } - public function checkBackup() : void { + public function checkBackup(?\Closure $addToStreamingResponseBody = null) : void { $this->configurationManager->backupMode = 'check'; $id = 'nextcloud-aio-borgbackup'; - $this->PerformRecursiveContainerStart($id); + $this->PerformRecursiveContainerStart($id, true, $addToStreamingResponseBody); } - private function listBackup() : void { + private function listBackup(?\Closure $addToStreamingResponseBody = null) : void { $this->configurationManager->backupMode = 'list'; $id = 'nextcloud-aio-borgbackup'; - $this->PerformRecursiveContainerStart($id); + $this->PerformRecursiveContainerStart($id, true, $addToStreamingResponseBody); } public function StartBackupContainerRestore(Request $request, Response $response, array $args) : Response { @@ -133,26 +154,38 @@ readonly class DockerController { $this->configurationManager->restoreExcludePreviews = isset($request->getParsedBody()['restore-exclude-previews']); $this->configurationManager->commitTransaction(); + // Get streaming response start and closure + $nonbufResp = $this->startStreamingResponse($response); + $addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp); + $id = self::TOP_CONTAINER; $forceStopNextcloud = true; - $this->PerformRecursiveContainerStop($id, $forceStopNextcloud); + $this->PerformRecursiveContainerStop($id, $forceStopNextcloud, $addToStreamingResponseBody); $id = 'nextcloud-aio-borgbackup'; - $this->PerformRecursiveContainerStart($id); + $this->PerformRecursiveContainerStart($id, true, $addToStreamingResponseBody); - return $response->withStatus(201)->withHeader('Location', '.'); + // End streaming response + $this->finalizeStreamingResponse($nonbufResp); + return $nonbufResp; } public function StartBackupContainerCheckRepair(Request $request, Response $response, array $args) : Response { $this->configurationManager->backupMode = 'check-repair'; + // Get streaming response start and closure + $nonbufResp = $this->startStreamingResponse($response); + $addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp); + $id = 'nextcloud-aio-borgbackup'; - $this->PerformRecursiveContainerStart($id); + $this->PerformRecursiveContainerStart($id, true, $addToStreamingResponseBody); // Restore to backup check which is needed to make the UI logic work correctly $this->configurationManager->backupMode = 'check'; - return $response->withStatus(201)->withHeader('Location', '.'); + // End streaming response + $this->finalizeStreamingResponse($nonbufResp); + return $nonbufResp; } public function StartBackupContainerTest(Request $request, Response $response, array $args) : Response { @@ -161,13 +194,19 @@ readonly class DockerController { $this->configurationManager->instanceRestoreAttempt = false; $this->configurationManager->commitTransaction(); + // Get streaming response start and closure + $nonbufResp = $this->startStreamingResponse($response); + $addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp); + $id = self::TOP_CONTAINER; - $this->PerformRecursiveContainerStop($id); + $this->PerformRecursiveContainerStop($id, true, $addToStreamingResponseBody); $id = 'nextcloud-aio-borgbackup'; - $this->PerformRecursiveContainerStart($id); + $this->PerformRecursiveContainerStart($id, true, $addToStreamingResponseBody); - return $response->withStatus(201)->withHeader('Location', '.'); + // End streaming response + $this->finalizeStreamingResponse($nonbufResp); + return $nonbufResp; } public function StartContainer(Request $request, Response $response, array $args) : Response @@ -202,14 +241,9 @@ readonly class DockerController { error_log('WARNING: Not pulling container images. Instead, using local ones.'); } + // Get streaming response start and closure $nonbufResp = $this->startStreamingResponse($response); - - // Create a closure to pass around to the code, which should to the logging (because it e.g. decides - // if it'll actually pull an image), but which should not need to know anything about the - // wanted markup or formatting. - $addToStreamingResponseBody = function (Container $container, string $message) use ($nonbufResp) : void { - $nonbufResp->getBody()->write("