From 3977b568be1ff7816fa62ba3c094a34cdd199c57 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Thu, 27 Jun 2024 11:04:48 +0200 Subject: [PATCH] Fix variable assignment and initialize `$links` array before use --- Classes/Hooks/KitodoProductionHacks.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Classes/Hooks/KitodoProductionHacks.php b/Classes/Hooks/KitodoProductionHacks.php index e0b247e01..526cdda20 100644 --- a/Classes/Hooks/KitodoProductionHacks.php +++ b/Classes/Hooks/KitodoProductionHacks.php @@ -39,12 +39,16 @@ public function postProcessRecordId(\SimpleXMLElement &$xml, &$recordId): void if (!$recordId) { $xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3'); // Get all logical structure nodes with metadata, but without associated METS-Pointers. - if (($divs = $xml->xpath('//mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID and not(./mets:mptr)]'))) { + $divs = $xml->xpath('//mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID and not(./mets:mptr)]'); + if (is_array($divs)) { $smLinks = $xml->xpath('//mets:structLink/mets:smLink'); if (!empty($smLinks)) { + $links = []; + foreach ($smLinks as $smLink) { $links[(string) $smLink->attributes('http://www.w3.org/1999/xlink')->from][] = (string) $smLink->attributes('http://www.w3.org/1999/xlink')->to; } + foreach ($divs as $div) { if (!empty($links[(string) $div['ID']])) { $id = (string) $div['DMDID'];