diff --git a/Classes/Command/BaseCommand.php b/Classes/Command/BaseCommand.php index 0fd39da1f8..2db3975825 100644 --- a/Classes/Command/BaseCommand.php +++ b/Classes/Command/BaseCommand.php @@ -176,6 +176,7 @@ protected function saveToDatabase(Document $document) if ($doc === null) { return false; } + $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); $doc->cPid = $this->storagePid; $metadata = $doc->getTitledata($this->storagePid); @@ -212,6 +213,8 @@ protected function saveToDatabase(Document $document) $documentCollection->setDescription(''); // add to CollectionRepository $this->collectionRepository->add($documentCollection); + // persist collection to prevent duplicates + $persistenceManager->persistAll(); } // add to document $document->addCollection($documentCollection); @@ -273,7 +276,6 @@ protected function saveToDatabase(Document $document) $this->documentRepository->update($document); } - $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); $persistenceManager->persistAll(); return true;