diff --git a/EMS/core-bundle/src/Command/Environment/AlignCommand.php b/EMS/core-bundle/src/Command/Environment/AlignCommand.php index 4e79ce7dc..f3d5d58c7 100644 --- a/EMS/core-bundle/src/Command/Environment/AlignCommand.php +++ b/EMS/core-bundle/src/Command/Environment/AlignCommand.php @@ -62,6 +62,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v $this->initializeRevisionSearcher(self::LOCK_USER); $this->publicationTemplate = $this->getOptionBool(self::OPTION_PUBLICATION_TEMPLATE); + $this->publishService->bulkStart($this->revisionSearcher->getSize(), $this->logger); } protected function interact(InputInterface $input, OutputInterface $output): void @@ -77,9 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $search = $this->revisionSearcher->create($this->source, $this->searchQuery); - $bulkSize = $this->revisionSearcher->getSize(); - - $this->io->note(\sprintf('The source environment contains %s elements, start aligning environments...', $search->getTotal())); + $this->io->section(\sprintf('The source environment contains %s elements, start aligning environments...', $search->getTotal())); if ($this->dryRun) { $this->io->success('Dry run finished'); @@ -88,14 +87,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $targetIsPreviewEnvironment = []; + $ouuids = []; $this->io->progressStart($search->getTotal()); foreach ($this->revisionSearcher->search($this->source, $search) as $revisions) { $this->revisionSearcher->lock($revisions, $this->lockUser); - $this->publishService->bulkStart($bulkSize, $this->logger); foreach ($revisions->transaction() as $revision) { $contentType = $revision->giveContentType(); + $ouuids[] = $revision->giveOuuid(); if ($revision->getDeleted()) { ++$this->counters['deleted']; @@ -112,11 +112,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->io->progressAdvance(); } - $this->publishService->bulkFinished(); $this->revisionSearcher->unlock($revisions); } + $this->publishService->bulkFinished(); $this->io->progressFinish(); + $this->unpublishNotAligned(...$ouuids); + $this->environmentService->clearCache(); if ($input->getOption(self::OPTION_SNAPSHOT)) { @@ -162,4 +164,40 @@ protected function execute(InputInterface $input, OutputInterface $output): int return self::EXECUTE_SUCCESS; } + + private function unpublishNotAligned(string ...$ouuids): void + { + $this->io->section(\sprintf('Unpublish not aligned documents from "%s"', $this->target->getName())); + $countUnpublished = 0; + + $targetSearch = $this->revisionSearcher->create($this->target, $this->searchQuery); + $this->io->progressStart($targetSearch->getTotal()); + + foreach ($this->revisionSearcher->search($this->target, $targetSearch) as $revisions) { + $this->revisionSearcher->lock($revisions, $this->lockUser); + + foreach ($revisions->transaction() as $revision) { + $this->io->progressAdvance(); + + if (\in_array($revision->getOuuid(), $ouuids, true)) { + continue; + } + + if ($revision->giveContentType()->giveEnvironment() === $this->target) { + $this->io->warning(\sprintf('Could not unpublish the document %s, target is default environment', $revision->getEmsLink())); + continue; + } + + $this->publishService->bulkUnpublish($revision, $this->target); + ++$countUnpublished; + } + + $this->revisionSearcher->unlock($revisions); + } + + $this->publishService->bulkFinished(); + $this->io->progressFinish(); + + $this->io->note(\sprintf('Unpublished %d documents from "%s"', $countUnpublished, $this->target->getName())); + } } diff --git a/EMS/core-bundle/src/Service/PublishService.php b/EMS/core-bundle/src/Service/PublishService.php index 20f08b423..6c7e3f8c6 100644 --- a/EMS/core-bundle/src/Service/PublishService.php +++ b/EMS/core-bundle/src/Service/PublishService.php @@ -161,10 +161,6 @@ public function bulkUnpublish(Revision $revision, Environment $environment): voi throw new \LogicException('Unpublish failed: is default environment'); } - if (1 === $this->environmentService->getPublishedForRevision($revision)->count()) { - throw new \LogicException('Unpublish failed: requires 1 environment'); - } - $revision->getEnvironments()->removeElement($environment); $this->bulker->delete($environment->getAlias(), $revision->giveOuuid()); } diff --git a/docs/upgrade.md b/docs/upgrade.md index c55edd340..cb374571e 100644 --- a/docs/upgrade.md +++ b/docs/upgrade.md @@ -13,6 +13,10 @@ * [version 4.x](#version-4x) * [Tips and tricks](#tips-and-tricks) +## version 5.25.x + +- The `emsco:environment:align` will after publication also unpublish documents that are not aligned. + ## version 5.23.x From this version, the upload of web's assets via the command `emsch:local:upload-assets` wont upload a zip anymore but each assets independently.