Skip to content

Commit

Permalink
[MAINTENANCE] Use parentHref for getting parent document uid while in…
Browse files Browse the repository at this point in the history
…dexing (#958)

Co-authored-by: Sebastian Meyer <[email protected]>
  • Loading branch information
beatrycze-volk and sebastian-meyer committed Sep 15, 2023
1 parent 87af845 commit bc51faa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
53 changes: 23 additions & 30 deletions Classes/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ protected function _getToplevelId()
/**
* Try to determine URL of parent document.
*
* @return string|null
* @return string
*/
public function _getParentHref()
{
Expand Down

0 comments on commit bc51faa

Please sign in to comment.