From d6e7306e838bf3490cd9a81f5e099e0b3a7a1aff Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:44:34 +0100 Subject: [PATCH] TASK: Validate `--remove-temporary-before` --- .../ContentStreamCommandController.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Neos.ContentRepositoryRegistry/Classes/Command/ContentStreamCommandController.php b/Neos.ContentRepositoryRegistry/Classes/Command/ContentStreamCommandController.php index 4a40dd2ea47..61325fb6a0e 100644 --- a/Neos.ContentRepositoryRegistry/Classes/Command/ContentStreamCommandController.php +++ b/Neos.ContentRepositoryRegistry/Classes/Command/ContentStreamCommandController.php @@ -63,17 +63,32 @@ public function statusCommand(string $contentRepository = 'default'): void * * To prune the removed content streams from the event stream, run ./flow contentStream:pruneRemovedFromEventStream afterwards. * + * NOTE: To ensure that no temporary content streams of the *current* moment are removed, a time threshold is configurable via --remove-temporary-before + * * @param string $contentRepository Identifier of the content repository. (Default: 'default') - * @param string $removeTemporaryBefore includes all temporary content streams like FORKED or CREATED older than that in the removal + * @param string $removeTemporaryBefore includes all temporary content streams like FORKED or CREATED older than that in the removal. To remove all use --remove-temporary-before=-1sec */ public function removeDanglingCommand(string $contentRepository = 'default', string $removeTemporaryBefore = '-1day'): void { $contentRepositoryId = ContentRepositoryId::fromString($contentRepository); $contentStreamPruner = $this->contentRepositoryRegistry->buildService($contentRepositoryId, new ContentStreamPrunerFactory()); + try { + $removeTemporaryBeforeDate = new \DateTimeImmutable($removeTemporaryBefore); + } catch (\Exception $exception) { + $this->outputLine(sprintf('--remove-temporary-before=%s is not a valid date: %s', $removeTemporaryBefore, $exception->getMessage())); + $this->quit(1); + } + + $now = new \DateTimeImmutable('now'); + if ($removeTemporaryBeforeDate > $now) { + $this->outputLine(sprintf('--remove-temporary-before=%s must be in the past', $removeTemporaryBefore)); + $this->quit(1); + } + $contentStreamPruner->removeDanglingContentStreams( $this->outputLine(...), - new \DateTimeImmutable($removeTemporaryBefore) + $removeTemporaryBeforeDate ); }