From 29147a5a864d5a9c90bf6c7c58c3ac691ca2c587 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:29:44 +0200 Subject: [PATCH 1/8] Adjustments to function names, splitted metadata function part --- module/VuFind/src/VuFind/OAI/Server.php | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index d63ee3d5310..fe7e3f014a7 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -36,6 +36,7 @@ use VuFind\Db\Service\ChangeTrackerServiceInterface; use VuFind\Db\Service\OaiResumptionServiceInterface; use VuFind\Exception\RecordMissing as RecordMissingException; +use VuFind\RecordDriver\AbstractBase as AbstractRecordDriver; use VuFind\SimpleXML; use VuFindApi\Formatter\RecordFormatter; @@ -444,17 +445,8 @@ protected function attachNonDeleted( $headerOnly = false, $set = '' ) { - // Get the XML (and display an error if it is unsupported): - if ($format === false) { - $xml = ''; // no metadata if in header-only mode! - } elseif ('oai_vufind_json' === $format && $this->supportsVuFindMetadata()) { - $xml = $this->getVuFindMetadata($record); // special case - } else { - $xml = $record - ->getXML($format, $this->baseHostURL, $this->recordLinkerHelper); - if ($xml === false) { - return false; - } + if ($format !== false) { + $xml = $this->getRecordAsXML($record, $format); } // Headers should be returned only if the metadata format matching @@ -492,7 +484,7 @@ protected function attachNonDeleted( ); // Inject metadata if necessary: - if (!$headerOnly && !empty($xml)) { + if (!$headerOnly) { $metadata = $recXml->addChild('metadata'); SimpleXML::appendElement($metadata, $xml); } @@ -500,6 +492,22 @@ protected function attachNonDeleted( return true; } + /** + * Get record as a metadata presentation + * + * @param AbstractRecordDriver $record A record driver object + * @param string $format Metadata format to obtain + * + * @return string|bool String on success or false if error occurs + */ + protected function getRecordAsXML(AbstractRecordDriver $record, string $format): string|false + { + if ('oai_vufind_json' === $format && $this->supportsVuFindMetadata()) { + return $this->getVuFindMetadata($record); // special case + } + return $record->getXML($format, $this->baseHostURL, $this->recordLinkerHelper); + } + /** * Respond to a GetRecord request. * From a83c10f384953256a8f121f6f403b07387655987 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:40:17 +0200 Subject: [PATCH 2/8] Readded comment --- module/VuFind/src/VuFind/OAI/Server.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index fe7e3f014a7..d4e2362d7b3 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -445,6 +445,7 @@ protected function attachNonDeleted( $headerOnly = false, $set = '' ) { + // no metadata if in header-only mode! if ($format !== false) { $xml = $this->getRecordAsXML($record, $format); } From 64e74e9917c196fc3c4109b4d8ee0626fce23512 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:03:03 +0200 Subject: [PATCH 3/8] Adjusted code to have a default_return key, return instantly if format is false. --- module/VuFind/src/VuFind/OAI/Server.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index d4e2362d7b3..35bc211d7c2 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -445,16 +445,18 @@ protected function attachNonDeleted( $headerOnly = false, $set = '' ) { - // no metadata if in header-only mode! - if ($format !== false) { - $xml = $this->getRecordAsXML($record, $format); + if ($format === false) { + return true; } + $result = $this->getRecordAsXML($record, $format); + $xml = $result['xml']; + // Headers should be returned only if the metadata format matching // the supplied metadataPrefix is available. // If RecordDriver returns nothing, skip this record. if (empty($xml)) { - return true; + return $result['default_return']; } // Check for sets: @@ -499,14 +501,21 @@ protected function attachNonDeleted( * @param AbstractRecordDriver $record A record driver object * @param string $format Metadata format to obtain * - * @return string|bool String on success or false if error occurs + * @return array [xml => record as xml or false on error, default_return => true for not displaying as error] */ - protected function getRecordAsXML(AbstractRecordDriver $record, string $format): string|false + protected function getRecordAsXML(AbstractRecordDriver $record, string $format): array { if ('oai_vufind_json' === $format && $this->supportsVuFindMetadata()) { - return $this->getVuFindMetadata($record); // special case + return [ + 'xml' => $this->getVuFindMetadata($record), + 'default_return' => true, + ]; } - return $record->getXML($format, $this->baseHostURL, $this->recordLinkerHelper); + $result = $record->getXML($format, $this->baseHostURL, $this->recordLinkerHelper); + return [ + 'xml' => $result, + 'default_return' => false, + ]; } /** From 76921174a6acf698884b1ad2a43ef72e5ff61980 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:05:57 +0200 Subject: [PATCH 4/8] Adjusted comment --- module/VuFind/src/VuFind/OAI/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index 35bc211d7c2..4fc8011e400 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -501,7 +501,7 @@ protected function attachNonDeleted( * @param AbstractRecordDriver $record A record driver object * @param string $format Metadata format to obtain * - * @return array [xml => record as xml or false on error, default_return => true for not displaying as error] + * @return array [xml => record as xml or false on error, default_return => true or false] */ protected function getRecordAsXML(AbstractRecordDriver $record, string $format): array { From b30cae072f8c6eaadb91e4de2231fac610de3a39 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:55:31 +0200 Subject: [PATCH 5/8] Adjusted return logic --- module/VuFind/src/VuFind/OAI/Server.php | 29 ++++++++++--------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index 4fc8011e400..3110c1bd5af 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -446,17 +446,17 @@ protected function attachNonDeleted( $set = '' ) { if ($format === false) { + // If no format was requested, report success without doing anything: return true; } - $result = $this->getRecordAsXML($record, $format); - $xml = $result['xml']; + $xml = $this->getRecordAsXML($record, $format); - // Headers should be returned only if the metadata format matching - // the supplied metadataPrefix is available. - // If RecordDriver returns nothing, skip this record. - if (empty($xml)) { - return $result['default_return']; + // If returned XML is false, an error was encountered during the process + // of generating the XML file. Return false for calling functions, so the + // error can be processed properly. + if (!$xml) { + return $xml !== false; } // Check for sets: @@ -501,21 +501,14 @@ protected function attachNonDeleted( * @param AbstractRecordDriver $record A record driver object * @param string $format Metadata format to obtain * - * @return array [xml => record as xml or false on error, default_return => true or false] + * @return string|false String or false if an error occured */ - protected function getRecordAsXML(AbstractRecordDriver $record, string $format): array + protected function getRecordAsXML(AbstractRecordDriver $record, string $format): string|false { if ('oai_vufind_json' === $format && $this->supportsVuFindMetadata()) { - return [ - 'xml' => $this->getVuFindMetadata($record), - 'default_return' => true, - ]; + return $this->getVuFindMetadata($record); } - $result = $record->getXML($format, $this->baseHostURL, $this->recordLinkerHelper); - return [ - 'xml' => $result, - 'default_return' => false, - ]; + return $record->getXML($format, $this->baseHostURL, $this->recordLinkerHelper); } /** From 4fcc5c73bd6d321edb3de2f540ce3d0317279cea Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:06:06 +0200 Subject: [PATCH 6/8] Adjusted comment, added BC return check for oai_vufind_json --- module/VuFind/src/VuFind/OAI/Server.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index 3110c1bd5af..1513032b9d1 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -452,9 +452,11 @@ protected function attachNonDeleted( $xml = $this->getRecordAsXML($record, $format); + // Headers should be returned only if the metadata format matching + // the supplied metadataPrefix is available. + // If returned XML is empty, return true to simply skip this record. // If returned XML is false, an error was encountered during the process - // of generating the XML file. Return false for calling functions, so the - // error can be processed properly. + // of generating the XML file. if (!$xml) { return $xml !== false; } @@ -506,7 +508,8 @@ protected function attachNonDeleted( protected function getRecordAsXML(AbstractRecordDriver $record, string $format): string|false { if ('oai_vufind_json' === $format && $this->supportsVuFindMetadata()) { - return $this->getVuFindMetadata($record); + // Return empty string instead of false for BC. + return $this->getVuFindMetadata($record) ?: ''; } return $record->getXML($format, $this->baseHostURL, $this->recordLinkerHelper); } From 220096c7abb912e2abceead1181881d1b9409ab8 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:00:35 +0200 Subject: [PATCH 7/8] Reverted bc support, handle as an error --- module/VuFind/src/VuFind/OAI/Server.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index 1513032b9d1..0c012af7d2d 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -508,8 +508,7 @@ protected function attachNonDeleted( protected function getRecordAsXML(AbstractRecordDriver $record, string $format): string|false { if ('oai_vufind_json' === $format && $this->supportsVuFindMetadata()) { - // Return empty string instead of false for BC. - return $this->getVuFindMetadata($record) ?: ''; + return $this->getVuFindMetadata($record); } return $record->getXML($format, $this->baseHostURL, $this->recordLinkerHelper); } From 984eec1c60dfe99098554ef14cd59f9ddeefc5be Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:15:31 +0200 Subject: [PATCH 8/8] Added comment --- module/VuFind/src/VuFind/OAI/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index 0c012af7d2d..98c367a6050 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -379,7 +379,7 @@ protected function attachRecordHeader( * * @param object $record A record driver object * - * @return string + * @return string|false String on success and false if an error occurred */ protected function getVuFindMetadata($record) {