Skip to content

Commit

Permalink
TASK: Validate --remove-temporary-before
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Oct 30, 2024
1 parent ff0dbab commit 3e7ac78
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Classes/Command/ContentStreamCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<error>--remove-temporary-before=%s is not a valid date</error>: %s', $removeTemporaryBefore, $exception->getMessage()));
$this->quit(1);
}

$now = new \DateTimeImmutable('now');
if ($removeTemporaryBeforeDate > $now) {
$this->outputLine(sprintf('<error>--remove-temporary-before=%s must be in the past</error>', $removeTemporaryBefore));
$this->quit(1);
}

$contentStreamPruner->removeDanglingContentStreams(
$this->outputLine(...),
new \DateTimeImmutable($removeTemporaryBefore)
$removeTemporaryBeforeDate
);
}

Expand Down

0 comments on commit 3e7ac78

Please sign in to comment.