diff --git a/Classes/Command/BaseCommand.php b/Classes/Command/BaseCommand.php index 4ae763117..7d600c985 100644 --- a/Classes/Command/BaseCommand.php +++ b/Classes/Command/BaseCommand.php @@ -306,36 +306,29 @@ protected function getParentDocumentUidForSaving(Document $document) { $doc = $document->getDoc(); - if ($doc !== null) { - // Same as MetsDocument::parentHref (TODO: Use it) - // Get the closest ancestor of the current document which has a MPTR child. - $parentMptr = $doc->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="' . $doc->toplevelId . '"]/ancestor::mets:div[./mets:mptr][1]/mets:mptr'); - if (!empty($parentMptr)) { - $parentLocation = (string) $parentMptr[0]->attributes('http://www.w3.org/1999/xlink')->href; - - // find document object by record_id of parent - $parentDoc = Doc::getInstance($parentLocation, ['storagePid' => $this->storagePid]); - - if ($parentDoc->recordId) { - $parentDocument = $this->documentRepository->findOneByRecordId($parentDoc->recordId); - - if ($parentDocument === null) { - // create new Document object - $parentDocument = GeneralUtility::makeInstance(Document::class); - } - - $parentDocument->setOwner($this->owner); - $parentDocument->setDoc($parentDoc); - $parentDocument->setLocation($parentLocation); - $parentDocument->setSolrcore($document->getSolrcore()); - - $success = $this->saveToDatabase($parentDocument); - - if ($success === true) { - // add to index - Indexer::add($parentDocument, $this->documentRepository); - return $parentDocument->getUid(); - } + if ($doc !== null && !empty($doc->parentHref)) { + // find document object by record_id of parent + $parentDoc = Doc::getInstance($doc->parentHref, ['storagePid' => $this->storagePid]); + + if ($parentDoc->recordId) { + $parentDocument = $this->documentRepository->findOneByRecordId($parentDoc->recordId); + + if ($parentDocument === null) { + // create new Document object + $parentDocument = GeneralUtility::makeInstance(Document::class); + } + + $parentDocument->setOwner($this->owner); + $parentDocument->setDoc($parentDoc); + $parentDocument->setLocation($doc->parentHref); + $parentDocument->setSolrcore($document->getSolrcore()); + + $success = $this->saveToDatabase($parentDocument); + + if ($success === true) { + // add to index + Indexer::add($parentDocument); + return $parentDocument->getUid(); } } } diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index ae651b87a..1f9d63660 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -1215,7 +1215,7 @@ protected function _getToplevelId() /** * Try to determine URL of parent document. * - * @return string|null + * @return string */ public function _getParentHref() {