Skip to content

Commit 4e4ba10

Browse files
[BUGFIX] Replace magic getter for toplevelId property (kitodo#1624)
Co-authored-by: Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
1 parent 70226ea commit 4e4ba10

6 files changed

Lines changed: 28 additions & 31 deletions

File tree

Classes/Common/AbstractDocument.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
* @property bool $tableOfContentsLoaded flag with information if the table of contents is loaded
5555
* @property-read string $thumbnail this holds the document's thumbnail location
5656
* @property bool $thumbnailLoaded flag with information if the thumbnail is loaded
57-
* @property-read string $toplevelId this holds the toplevel structure's "@ID" (METS) or the manifest's "@id" (IIIF)
5857
* @property \SimpleXMLElement $xml this holds the whole XML file as \SimpleXMLElement object
5958
*/
6059
abstract class AbstractDocument
@@ -454,13 +453,13 @@ abstract protected function magicGetThumbnail(bool $forceReload = false): string
454453
/**
455454
* This returns the ID of the toplevel logical structure node
456455
*
457-
* @access protected
456+
* @access public
458457
*
459458
* @abstract
460459
*
461460
* @return string The logical structure node's ID
462461
*/
463-
abstract protected function magicGetToplevelId(): string;
462+
abstract public function getToplevelId(): string;
464463

465464
/**
466465
* This sets some basic class properties
@@ -809,10 +808,10 @@ public static function getTitle(int $uid, bool $recursive = false): string
809808
*/
810809
public function getToplevelMetadata(int $cPid = 0): array
811810
{
812-
$toplevelMetadata = $this->getMetadata($this->magicGetToplevelId(), $cPid);
811+
$toplevelMetadata = $this->getMetadata($this->getToplevelId(), $cPid);
813812
// Add information from METS structural map to toplevel metadata array.
814813
if ($this instanceof MetsDocument) {
815-
$this->addMetadataFromMets($toplevelMetadata, $this->magicGetToplevelId());
814+
$this->addMetadataFromMets($toplevelMetadata, $this->getToplevelId());
816815
}
817816
// Set record identifier for METS file / IIIF manifest if not present.
818817
if (array_key_exists('record_id', $toplevelMetadata)) {

Classes/Common/IiifManifest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@
6565
* @property bool $tableOfContentsLoaded flag with information if the table of contents is loaded
6666
* @property-read string $thumbnail this holds the document's thumbnail location
6767
* @property bool $thumbnailLoaded flag with information if the thumbnail is loaded
68-
* @property-read string $toplevelId this holds the toplevel structure's "@ID" (METS) or the manifest's "@id" (IIIF)
6968
* @property \SimpleXMLElement $xml this holds the whole XML file as \SimpleXMLElement object
7069
* @property string $asJson this holds the manifest file as string for serialization purposes
7170
* @property ManifestInterface $iiif a PHP object representation of a IIIF manifest
7271
* @property string $iiifVersion 'IIIF1', 'IIIF2' or 'IIIF3', depending on the API $this->iiif conforms to
7372
* @property bool $hasFulltextSet flag if document has already been analyzed for presence of the fulltext for the Solr index
7473
* @property array $originalMetadataArray this holds the original manifest's parsed metadata array with their corresponding resource (Manifest / Sequence / Range) ID as array key
7574
* @property array $mimeTypes this holds the mime types of linked resources in the manifest (extracted during parsing) for later us
76-
*
75+
*
7776
*/
7877
final class IiifManifest extends AbstractDocument
7978
{
@@ -472,7 +471,7 @@ protected function getLogicalStructureInfo(IiifResourceInterface $resource, bool
472471
$details['volume'] = '';
473472
$details['pagination'] = '';
474473
$cPid = ($this->cPid ? $this->cPid : $this->pid);
475-
if ($details['id'] == $this->magicGetToplevelId()) {
474+
if ($details['id'] == $this->getToplevelId()) {
476475
$metadata = $this->getMetadata($details['id'], $cPid);
477476
if (!empty($metadata['type'][0])) {
478477
$details['type'] = $metadata['type'][0];
@@ -700,7 +699,7 @@ protected function magicGetSmLinks(): array
700699
* @access private
701700
*
702701
* @param RangeInterface $range Current range whose canvases shall be linked
703-
*
702+
*
704703
* @return void
705704
*/
706705
private function smLinkRangeCanvasesRecursively(RangeInterface $range): void
@@ -726,7 +725,7 @@ private function smLinkRangeCanvasesRecursively(RangeInterface $range): void
726725
*
727726
* @param CanvasInterface $canvas
728727
* @param IiifResourceInterface $resource
729-
*
728+
*
730729
* @return void
731730
*/
732731
private function smLinkCanvasToResource(CanvasInterface $canvas, IiifResourceInterface $resource): void
@@ -898,9 +897,9 @@ protected function magicGetThumbnail(bool $forceReload = false): string
898897
}
899898

900899
/**
901-
* @see AbstractDocument::magicGetToplevelId()
900+
* @see AbstractDocument::getToplevelId()
902901
*/
903-
protected function magicGetToplevelId(): string
902+
public function getToplevelId(): string
904903
{
905904
if (empty($this->toplevelId)) {
906905
if (isset($this->iiif)) {

Classes/Common/Indexer.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ protected static function processLogical(Document $document, array $logicalUnit)
348348
if (MathUtility::canBeInterpretedAsInteger($logicalUnit['points'])) {
349349
$solrDoc->setField('page', $logicalUnit['points']);
350350
}
351-
if ($logicalUnit['id'] == $doc->toplevelId) {
351+
if ($logicalUnit['id'] == $doc->getToplevelId()) {
352352
$solrDoc->setField('thumbnail', $doc->thumbnail);
353353
} elseif (!empty($logicalUnit['thumbnailId'])) {
354354
$solrDoc->setField('thumbnail', $doc->getFileLocation($logicalUnit['thumbnailId']));
355355
}
356356
// There can be only one toplevel unit per UID, independently of backend configuration
357-
$solrDoc->setField('toplevel', $logicalUnit['id'] == $doc->toplevelId ? true : false);
357+
$solrDoc->setField('toplevel', $logicalUnit['id'] == $doc->getToplevelId());
358358
$solrDoc->setField('title', $metadata['title'][0]);
359359
$solrDoc->setField('volume', $metadata['volume'][0]);
360360
// verify date formatting
@@ -385,9 +385,9 @@ protected static function processLogical(Document $document, array $logicalUnit)
385385
if (
386386
in_array('collection', self::$fields['facets'])
387387
&& empty($metadata['collection'])
388-
&& !empty($doc->metadataArray[$doc->toplevelId]['collection'])
388+
&& !empty($doc->metadataArray[$doc->getToplevelId()]['collection'])
389389
) {
390-
$solrDoc->setField('collection_faceting', $doc->metadataArray[$doc->toplevelId]['collection']);
390+
$solrDoc->setField('collection_faceting', $doc->metadataArray[$doc->getToplevelId()]['collection']);
391391
}
392392
try {
393393
$updateQuery->addDocument($solrDoc);
@@ -448,19 +448,19 @@ protected static function processPhysical(Document $document, int $page, array $
448448
}
449449
$solrDoc->setField('toplevel', false);
450450
$solrDoc->setField('type', $physicalUnit['type']);
451-
$solrDoc->setField('collection', $doc->metadataArray[$doc->toplevelId]['collection']);
451+
$solrDoc->setField('collection', $doc->metadataArray[$doc->getToplevelId()]['collection']);
452452
$solrDoc->setField('location', $document->getLocation());
453453

454454
$solrDoc->setField('fulltext', $fullText);
455-
if (is_array($doc->metadataArray[$doc->toplevelId])) {
455+
if (is_array($doc->metadataArray[$doc->getToplevelId()])) {
456456
self::addFaceting($doc, $solrDoc);
457457
}
458458
// Add collection information to physical sub-elements if applicable.
459459
if (
460460
in_array('collection', self::$fields['facets'])
461-
&& !empty($doc->metadataArray[$doc->toplevelId]['collection'])
461+
&& !empty($doc->metadataArray[$doc->getToplevelId()]['collection'])
462462
) {
463-
$solrDoc->setField('collection_faceting', $doc->metadataArray[$doc->toplevelId]['collection']);
463+
$solrDoc->setField('collection_faceting', $doc->metadataArray[$doc->getToplevelId()]['collection']);
464464
}
465465
try {
466466
$updateQuery->addDocument($solrDoc);
@@ -555,7 +555,7 @@ private static function processMetadata($document, $metadata, &$solrDoc): array
555555
private static function addFaceting($doc, &$solrDoc): void
556556
{
557557
// TODO: Include also subentries if available.
558-
foreach ($doc->metadataArray[$doc->toplevelId] as $indexName => $data) {
558+
foreach ($doc->metadataArray[$doc->getToplevelId()] as $indexName => $data) {
559559
if (
560560
!empty($data)
561561
&& substr($indexName, -8) !== '_sorting'
@@ -575,7 +575,7 @@ private static function addFaceting($doc, &$solrDoc): void
575575
!empty($data)
576576
&& substr($indexName, -8) == '_sorting'
577577
) {
578-
$solrDoc->setField($indexName, $doc->metadataArray[$doc->toplevelId][$indexName]);
578+
$solrDoc->setField($indexName, $doc->metadataArray[$doc->getToplevelId()][$indexName]);
579579
}
580580
}
581581
}
@@ -632,7 +632,7 @@ private static function getSolrDocument(Query $updateQuery, Document $document,
632632
$solrDoc->setField('root', $document->getCurrentDocument()->rootId);
633633
$solrDoc->setField('sid', $unit['id']);
634634
$solrDoc->setField('type', $unit['type']);
635-
$solrDoc->setField('collection', $document->getCurrentDocument()->metadataArray[$document->getCurrentDocument()->toplevelId]['collection']);
635+
$solrDoc->setField('collection', $document->getCurrentDocument()->metadataArray[$document->getCurrentDocument()->getToplevelId()]['collection']);
636636
$solrDoc->setField('fulltext', $fullText);
637637
return $solrDoc;
638638
}

Classes/Common/MetsDocument.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
* @property bool $tableOfContentsLoaded flag with information if the table of contents is loaded
6262
* @property-read string $thumbnail this holds the document's thumbnail location
6363
* @property bool $thumbnailLoaded flag with information if the thumbnail is loaded
64-
* @property-read string $toplevelId this holds the toplevel structure's "@ID" (METS) or the manifest's "@id" (IIIF)
6564
* @property SimpleXMLElement $xml this holds the whole XML file as SimpleXMLElement object
6665
* @property-read array $mdSec associative array of METS metadata sections indexed by their IDs.
6766
* @property bool $mdSecLoaded flag with information if the array of METS metadata sections is loaded
@@ -463,7 +462,7 @@ private function getPage(array &$details, ?SimpleXMLElement $metsPointers): void
463462
$details['thumbnailId'] = $this->getThumbnail();
464463
// Get page/track number of the first page/track related to this structure element.
465464
$details['pagination'] = $this->physicalStructureInfo[$this->smLinks['l2p'][$details['id']][0]]['orderlabel'];
466-
} elseif ($details['id'] == $this->magicGetToplevelId()) {
465+
} elseif ($details['id'] == $this->getToplevelId()) {
467466
// Point to self if this is the toplevel structure.
468467
$details['points'] = 1;
469468
$details['thumbnailId'] = $this->getThumbnail();
@@ -1579,7 +1578,7 @@ protected function magicGetThumbnail(bool $forceReload = false): string
15791578
$this->thumbnailLoaded = true;
15801579
return $this->thumbnail;
15811580
}
1582-
$strctId = $this->magicGetToplevelId();
1581+
$strctId = $this->getToplevelId();
15831582
$metadata = $this->getToplevelMetadata($cPid);
15841583

15851584
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
@@ -1639,9 +1638,9 @@ protected function magicGetThumbnail(bool $forceReload = false): string
16391638
}
16401639

16411640
/**
1642-
* @see AbstractDocument::magicGetToplevelId()
1641+
* @see AbstractDocument::getToplevelId()
16431642
*/
1644-
protected function magicGetToplevelId(): string
1643+
public function getToplevelId(): string
16451644
{
16461645
if (empty($this->toplevelId)) {
16471646
// Get all logical structure nodes with metadata, but without associated METS-Pointers.
@@ -1677,7 +1676,7 @@ public function magicGetParentHref(): string
16771676
{
16781677
if (empty($this->parentHref)) {
16791678
// Get the closest ancestor of the current document which has a MPTR child.
1680-
$parentMptr = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="' . $this->toplevelId . '"]/ancestor::mets:div[./mets:mptr][1]/mets:mptr');
1679+
$parentMptr = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="' . $this->getToplevelId() . '"]/ancestor::mets:div[./mets:mptr][1]/mets:mptr');
16811680
if (!empty($parentMptr)) {
16821681
$this->parentHref = (string) $parentMptr[0]->attributes('http://www.w3.org/1999/xlink')->href;
16831682
}

Classes/Controller/MetadataController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function mainAction(): void
115115
$this->useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->currentDocument instanceof IiifManifest;
116116

117117
$metadata = $this->getMetadata();
118-
$topLevelId = $this->currentDocument->toplevelId;
118+
$topLevelId = $this->currentDocument->getToplevelId();
119119
// Get toplevel metadata?
120120
if (!$metadata || ($this->settings['rootline'] == 1 && $metadata[0]['_id'] != $topLevelId)) {
121121
$data = [];

Classes/Controller/ToolboxController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ private function getWorkLink(): string
463463
$workLink = $this->currentDocument->getFileLocation($fileGroupDownload);
464464
break;
465465
} else {
466-
$details = $this->currentDocument->getLogicalStructure($this->currentDocument->toplevelId);
466+
$details = $this->currentDocument->getLogicalStructure($this->currentDocument->getToplevelId());
467467
if (!empty($details['files'][$fileGrpDownload])) {
468468
$workLink = $this->currentDocument->getFileLocation($details['files'][$fileGrpDownload]);
469469
break;

0 commit comments

Comments
 (0)