Skip to content

Commit 4b3a130

Browse files
[BUGFIX] Fix regression for METS files without physical structure (kitodo#1417)
Signed-off-by: Stefan Weil <sw@weilnetz.de> Co-authored-by: Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
1 parent b452185 commit 4b3a130

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

Classes/Common/MetsDocument.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,19 @@ private function getThumbnail(string $id = '')
484484

485485
$thumbnail = null;
486486

487-
while ($fileGrpThumb = array_shift($fileGrpsThumb)) {
488-
if (empty($id)) {
489-
$thumbnail = $this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb] ?? null;
490-
} else {
491-
$parentId = $this->smLinks['l2p'][$id][0] ?? null;
492-
$thumbnail = $this->physicalStructureInfo[$parentId]['files'][$fileGrpThumb] ?? null;
493-
}
487+
if (!empty($this->physicalStructure)) {
488+
// There is a physical structure (no anchor or year mets).
489+
while ($fileGrpThumb = array_shift($fileGrpsThumb)) {
490+
if (empty($id)) {
491+
$thumbnail = $this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb] ?? null;
492+
} else {
493+
$parentId = $this->smLinks['l2p'][$id][0] ?? null;
494+
$thumbnail = $this->physicalStructureInfo[$parentId]['files'][$fileGrpThumb] ?? null;
495+
}
494496

495-
if (!empty($thumbnail)) {
496-
break;
497+
if (!empty($thumbnail)) {
498+
break;
499+
}
497500
}
498501
}
499502
return $thumbnail;

Classes/Controller/CalendarController.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ protected function getCalendarYear(array &$calendarData, array $calendarIssuesBy
286286
$dayLinksText = [];
287287
$dayLinkDiv = [];
288288
$currentMonth = date('n', $currentDayTime);
289-
if (is_array($calendarIssuesByMonth[$currentMonth])) {
289+
if (array_key_exists($currentMonth, $calendarIssuesByMonth) && is_array($calendarIssuesByMonth[$currentMonth])) {
290290
foreach ($calendarIssuesByMonth[$currentMonth] as $id => $day) {
291291
if ($id == date('j', $currentDayTime)) {
292292
$dayLinks = $id;
@@ -492,19 +492,21 @@ private function getIssuesFromTableOfContents(): Generator
492492
$toc = $this->document->getCurrentDocument()->tableOfContents;
493493

494494
foreach ($toc[0]['children'] as $year) {
495-
foreach ($year['children'] as $month) {
496-
foreach ($month['children'] as $day) {
497-
foreach ($day['children'] as $issue) {
498-
$title = $issue['label'] ?: $issue['orderlabel'];
499-
if (strtotime($title) !== false) {
500-
$title = strftime('%x', strtotime($title));
501-
}
495+
if (array_key_exists('children', $year)) {
496+
foreach ($year['children'] as $month) {
497+
foreach ($month['children'] as $day) {
498+
foreach ($day['children'] as $issue) {
499+
$title = $issue['label'] ?: $issue['orderlabel'];
500+
if (strtotime($title) !== false) {
501+
$title = strftime('%x', strtotime($title));
502+
}
502503

503-
yield [
504-
'uid' => $issue['points'],
505-
'title' => $title,
506-
'year' => $day['orderlabel'],
507-
];
504+
yield [
505+
'uid' => $issue['points'],
506+
'title' => $title,
507+
'year' => $day['orderlabel'],
508+
];
509+
}
508510
}
509511
}
510512
}

Classes/Controller/MetadataController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ private function getMetadata(): array
478478
if ($this->settings['rootline'] < 2) {
479479
// Get current structure's @ID.
480480
$ids = [];
481-
if (isset($this->requestData['page'])) {
481+
if (!empty($this->currentDocument->physicalStructure) && isset($this->requestData['page'])) {
482482
$page = $this->currentDocument->physicalStructure[$this->requestData['page']];
483483
if (!empty($page) && !empty($this->currentDocument->smLinks['p2l'][$page])) {
484484
foreach ($this->currentDocument->smLinks['p2l'][$page] as $logId) {

0 commit comments

Comments
 (0)