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

[MAINTENANCE] Use parentHref for getting parent document uid while indexing #958

Merged
merged 3 commits into from
May 24, 2023
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
53 changes: 23 additions & 30 deletions Classes/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,36 +295,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);
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