mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-05-30 07:20:09 +00:00
Refactor creating and using addToStreamingResponseBody()
This way we stick to having one implementation of the function, not three. Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
@@ -299,7 +299,7 @@ readonly class DockerController {
|
||||
}
|
||||
|
||||
if ($addToStreamingResponseBody !== null) {
|
||||
$addToStreamingResponseBody($container, "Stopping container");
|
||||
$addToStreamingResponseBody("Stopping container", $container);
|
||||
}
|
||||
|
||||
// Stop itself first and then all the dependencies
|
||||
@@ -339,7 +339,7 @@ readonly class DockerController {
|
||||
|
||||
// Get streaming response start and closure
|
||||
$nonbufResp = $this->startStreamingResponse($response);
|
||||
$addToStreamingResponseBody = $this->getPlainStreamingCallback($nonbufResp);
|
||||
$addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp);
|
||||
|
||||
$this->dockerActionManager->RunNextcloudUpgradeToLatestMajor($addToStreamingResponseBody);
|
||||
|
||||
@@ -353,9 +353,7 @@ readonly class DockerController {
|
||||
$nonbufResp = $this->startStreamingResponse($response);
|
||||
|
||||
$body = $nonbufResp->getBody();
|
||||
$addToStreamingResponseBody = function (string $message) use ($body) : void {
|
||||
$body->write("<div>$message</div>");
|
||||
};
|
||||
$addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp);
|
||||
|
||||
$this->dockerActionManager->SystemPrune($addToStreamingResponseBody);
|
||||
|
||||
@@ -444,19 +442,16 @@ readonly class DockerController {
|
||||
// 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("<div>" . htmlspecialchars("{$container->displayName}: {$message}", ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . "</div>");
|
||||
$addToStreamingResponseBody = function (string $message, ?Container $container = null) use ($nonbufResp) : void {
|
||||
if ($container) {
|
||||
$message = "{$container->displayName}: {$message}";
|
||||
}
|
||||
$nonbufResp->getBody()->write("<div>" . htmlspecialchars("{$message}", ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . "</div>");
|
||||
};
|
||||
|
||||
return $addToStreamingResponseBody;
|
||||
}
|
||||
|
||||
private function getPlainStreamingCallback(Response $nonbufResp) : \Closure {
|
||||
return function (string $message) use ($nonbufResp) : void {
|
||||
$nonbufResp->getBody()->write("<div>" . htmlspecialchars($message, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . "</div>");
|
||||
};
|
||||
}
|
||||
|
||||
private function finalizeStreamingResponse(Response $nonbufResp) : void {
|
||||
$nonbufResp->getBody()->write($this->getStreamingResponseHtmlEnd());
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ readonly class DockerActionManager {
|
||||
$url = $this->BuildApiUrl(sprintf('containers/%s/start', urlencode($container->identifier)));
|
||||
try {
|
||||
if ($addToStreamingResponseBody !== null) {
|
||||
$addToStreamingResponseBody($container, "Starting container");
|
||||
$addToStreamingResponseBody("Starting container", $container);
|
||||
}
|
||||
$this->guzzleClient->post($url);
|
||||
} catch (RequestException $e) {
|
||||
@@ -550,7 +550,7 @@ readonly class DockerActionManager {
|
||||
$imageIsThere = true;
|
||||
try {
|
||||
if ($addToStreamingResponseBody) {
|
||||
$addToStreamingResponseBody($container, "Pulling image");
|
||||
$addToStreamingResponseBody("Pulling image", $container);
|
||||
}
|
||||
$imageUrl = $this->BuildApiUrl(sprintf('images/%s/json', $encodedImageName));
|
||||
$this->guzzleClient->get($imageUrl)->getBody()->getContents();
|
||||
|
||||
Reference in New Issue
Block a user