Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split OAI server attachNonDeleted function #4160

Merged
merged 8 commits into from
Dec 18, 2024
42 changes: 30 additions & 12 deletions module/VuFind/src/VuFind/OAI/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -444,24 +445,18 @@ 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;
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
}
return true;
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
}

$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:
Expand Down Expand Up @@ -492,14 +487,37 @@ protected function attachNonDeleted(
);

// Inject metadata if necessary:
if (!$headerOnly && !empty($xml)) {
if (!$headerOnly) {
$metadata = $recXml->addChild('metadata');
SimpleXML::appendElement($metadata, $xml);
}

return true;
}

/**
* Get record as a metadata presentation
*
* @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]
*/
protected function getRecordAsXML(AbstractRecordDriver $record, string $format): array
{
if ('oai_vufind_json' === $format && $this->supportsVuFindMetadata()) {
return [
'xml' => $this->getVuFindMetadata($record),
'default_return' => true,
];
}
$result = $record->getXML($format, $this->baseHostURL, $this->recordLinkerHelper);
return [
'xml' => $result,
'default_return' => false,
];
}

/**
* Respond to a GetRecord request.
*
Expand Down
Loading