Skip to content

Commit c4e68a6

Browse files
authored
[BUGFIX] Catch several issues with illegal operations on NULL (kitodo#1423)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 715c91c commit c4e68a6

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

Classes/Command/BaseCommand.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,29 +230,29 @@ protected function saveToDatabase(Document $document): bool
230230
}
231231

232232
// set identifiers
233-
$document->setProdId($metadata['prod_id'][0] ? : '');
234-
$document->setOpacId($metadata['opac_id'][0] ? : '');
235-
$document->setUnionId($metadata['union_id'][0] ? : '');
233+
$document->setProdId($metadata['prod_id'][0] ?? '');
234+
$document->setOpacId($metadata['opac_id'][0] ?? '');
235+
$document->setUnionId($metadata['union_id'][0] ?? '');
236236

237-
$document->setRecordId($metadata['record_id'][0] ? : ''); // (?) $doc->recordId
238-
$document->setUrn($metadata['urn'][0] ? : '');
239-
$document->setPurl($metadata['purl'][0] ? : '');
240-
$document->setDocumentFormat($metadata['document_format'][0] ? : '');
237+
$document->setRecordId($metadata['record_id'][0] ?? ''); // (?) $doc->recordId
238+
$document->setUrn($metadata['urn'][0] ?? '');
239+
$document->setPurl($metadata['purl'][0] ?? '');
240+
$document->setDocumentFormat($metadata['document_format'][0] ?? '');
241241

242242
// set access
243-
$document->setLicense($metadata['license'][0] ? : '');
244-
$document->setTerms($metadata['terms'][0] ? : '');
245-
$document->setRestrictions($metadata['restrictions'][0] ? : '');
246-
$document->setOutOfPrint($metadata['out_of_print'][0] ? : '');
247-
$document->setRightsInfo($metadata['rights_info'][0] ? : '');
243+
$document->setLicense($metadata['license'][0] ?? '');
244+
$document->setTerms($metadata['terms'][0] ?? '');
245+
$document->setRestrictions($metadata['restrictions'][0] ?? '');
246+
$document->setOutOfPrint($metadata['out_of_print'][0] ?? '');
247+
$document->setRightsInfo($metadata['rights_info'][0] ?? '');
248248
$document->setStatus(0);
249249

250-
$this->setOwner($metadata['owner'][0]);
250+
$this->setOwner($metadata['owner'][0] ?? '');
251251
$document->setOwner($this->owner);
252252

253253
// set volume data
254-
$document->setVolume($metadata['volume'][0] ? : '');
255-
$document->setVolumeSorting($metadata['volume_sorting'][0] ? : $metadata['mets_order'][0] ? : '');
254+
$document->setVolume($metadata['volume'][0] ?? '');
255+
$document->setVolumeSorting($metadata['volume_sorting'][0] ?? $metadata['mets_order'][0] ?? '');
256256

257257
// Get UID of parent document.
258258
if ($document->getDocumentFormat() === 'METS') {
@@ -290,7 +290,7 @@ protected function getParentDocumentUidForSaving(Document $document): int
290290
// find document object by record_id of parent
291291
$parent = AbstractDocument::getInstance($doc->parentHref, ['storagePid' => $this->storagePid]);
292292

293-
if ($parent->recordId) {
293+
if ($parent && $parent->recordId) {
294294
$parentDocument = $this->documentRepository->findOneByRecordId($parent->recordId);
295295

296296
if ($parentDocument === null) {

Classes/Command/IndexCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private function getDocumentFromUrl($doc, string $url): Document
210210
{
211211
$document = null;
212212

213-
if ($doc->recordId) {
213+
if ($doc and $doc->recordId) {
214214
$document = $this->documentRepository->findOneByRecordId($doc->recordId);
215215
} else {
216216
$document = $this->documentRepository->findOneByLocation($url);

Classes/Common/MetsDocument.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,18 @@ private function getThumbnail(string $id = '')
435435

436436
$thumbnail = null;
437437

438-
while ($fileGrpThumb = array_shift($fileGrpsThumb)) {
439-
if (empty($id)) {
440-
$thumbnail = $this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb] ?? null;
441-
} else {
442-
$parentId = $this->smLinks['l2p'][$id][0] ?? null;
443-
$thumbnail = $this->physicalStructureInfo[$parentId]['files'][$fileGrpThumb] ?? null;
444-
}
438+
if (!empty($this->physicalStructure)) {
439+
while ($fileGrpThumb = array_shift($fileGrpsThumb)) {
440+
if (empty($id)) {
441+
$thumbnail = $this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb] ?? null;
442+
} else {
443+
$parentId = $this->smLinks['l2p'][$id][0] ?? null;
444+
$thumbnail = $this->physicalStructureInfo[$parentId]['files'][$fileGrpThumb] ?? null;
445+
}
445446

446-
if (!empty($thumbnail)) {
447-
break;
447+
if (!empty($thumbnail)) {
448+
break;
449+
}
448450
}
449451
}
450452
return $thumbnail;
@@ -1416,7 +1418,10 @@ protected function magicGetThumbnail(bool $forceReload = false): string
14161418
) {
14171419
$this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->smLinks['l2p'][$strctId][0]]['files'][$fileGrpThumb]);
14181420
break;
1419-
} elseif (!empty($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb])) {
1421+
} elseif (
1422+
!empty($this->physicalStructure)
1423+
&& !empty($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb])
1424+
) {
14201425
$this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb]);
14211426
break;
14221427
}

Classes/Controller/MetadataController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ private function getMetadata(): array
464464
if ($this->settings['rootline'] < 2) {
465465
// Get current structure's @ID.
466466
$ids = [];
467-
$page = $this->currentDocument->physicalStructure[$this->requestData['page']];
467+
$page = $this->currentDocument->physicalStructure[$this->requestData['page']] ?? [];
468468
if (!empty($page) && !empty($this->currentDocument->smLinks['p2l'][$page])) {
469469
foreach ($this->currentDocument->smLinks['p2l'][$page] as $logId) {
470470
$count = $this->currentDocument->getStructureDepth($logId);

0 commit comments

Comments
 (0)