From 3ea5371979af286a1828d188d010352a219eb540 Mon Sep 17 00:00:00 2001 From: Matija Kancijan Date: Thu, 14 Jul 2022 11:23:54 +0200 Subject: [PATCH] chore: override plain record list with set scope --- index.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 71949cb..8271413 100644 --- a/index.php +++ b/index.php @@ -116,16 +116,28 @@ $oai2 = new Server( } }, 'ListRecords' => function ($metadataPrefix, $from = null, $until = null, $count = false, $deliveredRecords = 0, $maxItems = 100, $set = null) { - global $records, $deleted, $timestamps; + global $records, $deleted, $timestamps, $setsrecords; $resultSet = []; - foreach ($timestamps[$metadataPrefix] as $timestamp => $identifiers) { + + $currTimestamps = $timestamps; + $activeRecords = $records; + $deletedRecords = $deleted; + + // override with SET records. + if (isset($set)) { + $activeRecords = $setsrecords[$set]['records']; + $currTimestamps = $setsrecords[$set]['timestamps']; + $deletedRecords = $setsrecords[$set]['deleted']; + } + + foreach ($currTimestamps[$metadataPrefix] as $timestamp => $identifiers) { if ((is_null($from) || $timestamp >= $from) && (is_null($until) || $timestamp <= $until)) { foreach ($identifiers as $identifier) { $resultSet[] = [ 'identifier' => $identifier, - 'timestamp' => filemtime($records[$metadataPrefix][$identifier]), - 'deleted' => $deleted[$metadataPrefix][$identifier], - 'metadata' => $records[$metadataPrefix][$identifier] + 'timestamp' => filemtime($activeRecords[$metadataPrefix][$identifier]), + 'deleted' => $deletedRecords[$metadataPrefix][$identifier], + 'metadata' => $activeRecords[$metadataPrefix][$identifier] ]; } }