diff --git a/EMS/core-bundle/src/Command/Revision/DeleteCommand.php b/EMS/core-bundle/src/Command/Revision/DeleteCommand.php index c616214f5..3299499c2 100644 --- a/EMS/core-bundle/src/Command/Revision/DeleteCommand.php +++ b/EMS/core-bundle/src/Command/Revision/DeleteCommand.php @@ -22,6 +22,7 @@ class DeleteCommand extends AbstractCommand private const ARGUMENT_CONTENT_TYPES = 'content-types'; private const OPTION_MODE = 'mode'; private const OPTION_QUERY = 'query'; + private const OPTION_OUUID = 'ouuid'; private const MODE_ALL = 'all'; private const MODE_BY_QUERY = 'by-query'; @@ -49,6 +50,7 @@ protected function configure(): void ->addArgument(self::ARGUMENT_CONTENT_TYPES, InputArgument::IS_ARRAY, 'contentType names or "all"') ->addOption(self::OPTION_MODE, null, InputOption::VALUE_REQUIRED, 'mode for deletion [all,oldest,by-query]', 'all') ->addOption(self::OPTION_QUERY, null, InputOption::VALUE_OPTIONAL, 'query to use in by-query mode') + ->addOption(self::OPTION_OUUID, null, InputOption::VALUE_OPTIONAL, 'OUUID of the document to delete') ; } @@ -75,7 +77,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->io->title('EMSCO - Revision - Delete'); $queryJson = $this->getOptionStringNull(self::OPTION_QUERY); + $ouuid = $this->getOptionStringNull(self::OPTION_OUUID); if (self::MODE_BY_QUERY === $this->mode) { + if (null !== $ouuid) { + throw new \RuntimeException(\sprintf('The %s option is forbidden in %s mode', self::OPTION_OUUID, $this->mode)); + } + return $this->deleteByQuery($queryJson); } if (null !== $queryJson) { @@ -89,11 +96,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->io->section(\sprintf('Content Type: %s', $contentTypeName)); if (self::MODE_ALL === $this->mode) { + if (null !== $ouuid) { + throw new \RuntimeException(\sprintf('The %s option is forbidden in %s mode', self::OPTION_OUUID, $this->mode)); + } $this->publishService->unpublishByContentType($contentType); $result = $this->revisionService->deleteByContentType($contentType); $results[] = \sprintf('Deleted all %d "%s" revisions', $result, $contentTypeName); } elseif (self::MODE_OLDEST === $this->mode) { - $result = $this->revisionService->deleteOldest($contentType); + $result = $this->revisionService->deleteOldest($contentType, $ouuid); $results[] = \sprintf('Deleted oldest %d "%s" revisions', $result, $contentTypeName); } } diff --git a/EMS/core-bundle/src/Repository/RevisionRepository.php b/EMS/core-bundle/src/Repository/RevisionRepository.php index b43327862..283f84b63 100644 --- a/EMS/core-bundle/src/Repository/RevisionRepository.php +++ b/EMS/core-bundle/src/Repository/RevisionRepository.php @@ -524,7 +524,7 @@ public function publishRevision(Revision $revision, bool $draft = false): int return (int) $qb->getQuery()->execute(); } - public function deleteOldest(ContentType $contentType): int + public function deleteOldest(ContentType $contentType, ?string $ouuid): int { $conn = $this->_em->getConnection(); @@ -543,6 +543,10 @@ public function deleteOldest(ContentType $contentType): int ->andWhere($qbSelect->expr()->lt('r.start_time', 'sub.minStartTime')) ->andWhere($qbSelect->expr()->eq('c.id', ':content_type_id')) ->setParameter('content_type_id', $contentType->getId()); + if (null !== $ouuid) { + $qbSelect->andWhere($qbSelect->expr()->eq('r.ouuid', ':ouuid')) + ->setParameter('ouuid', $ouuid); + } return $this->deleteByQueryBuilder($qbSelect); } diff --git a/EMS/core-bundle/src/Service/Revision/RevisionService.php b/EMS/core-bundle/src/Service/Revision/RevisionService.php index c18f26e72..a35dfa7a2 100644 --- a/EMS/core-bundle/src/Service/Revision/RevisionService.php +++ b/EMS/core-bundle/src/Service/Revision/RevisionService.php @@ -119,9 +119,9 @@ public function deleteByOuuids(array $ouuids): int return $this->revisionRepository->deleteByOuuids($ouuids); } - public function deleteOldest(ContentType $contentType): int + public function deleteOldest(ContentType $contentType, ?string $ouuid): int { - return $this->revisionRepository->deleteOldest($contentType); + return $this->revisionRepository->deleteOldest($contentType, $ouuid); } public function display(Revision|Document|string $value, ?string $expression = null): string