Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin/environment): cli align unpublish not published documents #1089

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions EMS/core-bundle/src/Command/Environment/AlignCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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'];
Expand All @@ -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)) {
Expand Down Expand Up @@ -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()));
}
}
4 changes: 0 additions & 4 deletions EMS/core-bundle/src/Service/PublishService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 4 additions & 0 deletions docs/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading