From 27718bacc9e38d84ec1741ab441b203e143cccc7 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Fri, 9 Aug 2024 13:29:25 +0300 Subject: [PATCH] Sierra: Add support for harvesting authority records. --- conf/datasources.ini.sample | 5 ++++- src/RecordManager/Base/Harvest/SierraApi.php | 22 ++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/conf/datasources.ini.sample b/conf/datasources.ini.sample index 03ed30a1..9d17fa64 100644 --- a/conf/datasources.ini.sample +++ b/conf/datasources.ini.sample @@ -199,7 +199,10 @@ ;type = sierra ;sierraApiKey = "[api_key]" ;sierraApiSecret = "[api_secret]" -;sierraApiVersion = 5 +;sierraApiVersion = 6 +; Sierra API endpoint can be bibs for bibliographic records (default) or authorities +; for authority records +;sierraApiEndpoint = bibs ;url = https://kirjtuo1.helmet.fi/iii/sierra-api ;batchSize = 100 ;; Support for asking for non-suppressed records exists with the setting below, but as diff --git a/src/RecordManager/Base/Harvest/SierraApi.php b/src/RecordManager/Base/Harvest/SierraApi.php index 6aded878..ee7ac68c 100644 --- a/src/RecordManager/Base/Harvest/SierraApi.php +++ b/src/RecordManager/Base/Harvest/SierraApi.php @@ -131,9 +131,19 @@ class SierraApi extends AbstractBase /** * Fields to request from Sierra * + * @var array + */ + protected $harvestFields = [ + 'bibs' => 'default,locations,fixedFields,varFields,catalogDate', + 'authorities' => 'default,varFields,createdDate', + ]; + + /** + * Sierra API endpoint to use + * * @var string */ - protected $harvestFields = 'default,locations,fixedFields,varFields,catalogDate'; + protected $endpoint = 'bibs'; /** * Initialize harvesting @@ -166,6 +176,7 @@ public function init(string $source, bool $verbose, bool $reharvest): void ); $this->apiVersion = 'v' . ($settings['sierraApiVersion'] ?? '6'); $this->keepExisting852Fields = $settings['keepExisting852Fields'] ?? false; + $this->endpoint = $settings['sierraApiEndpoint'] ?? 'bibs'; } /** @@ -195,7 +206,7 @@ public function harvest($callback) $apiParams = [ 'limit' => $this->batchSize, 'offset' => $this->startPosition, - 'fields' => $this->harvestFields, + 'fields' => $this->harvestFields[$this->endpoint] ?? '', ]; if (null !== $this->suppressedRecords) { $apiParams['suppressed'] = $this->suppressedRecords ? 'true' : 'false'; @@ -215,7 +226,7 @@ public function harvest($callback) // Keep harvesting as long as a records are received: do { - $response = $this->sendRequest([$this->apiVersion, 'bibs'], $apiParams); + $response = $this->sendRequest([$this->apiVersion, $this->endpoint], $apiParams); $count = $this->processResponse((string)$response->getBody()); $this->reportResults(); $apiParams['offset'] += $apiParams['limit']; @@ -237,8 +248,7 @@ public function harvest($callback) // Keep harvesting as long as a records are received: do { - $response - = $this->sendRequest([$this->apiVersion, 'bibs'], $apiParams); + $response = $this->sendRequest([$this->apiVersion, $this->endpoint], $apiParams); $count = $this->processResponse((string)$response->getBody()); $this->reportResults(); $apiParams['offset'] += $apiParams['limit']; @@ -274,7 +284,7 @@ public function harvestSingle(callable $callback, string $id): void $apiParams['suppressed'] = $this->suppressedRecords ? 'true' : 'false'; } - $response = $this->sendRequest([$this->apiVersion, 'bibs'], $apiParams); + $response = $this->sendRequest([$this->apiVersion, $this->endpoint], $apiParams); $this->processResponse((string)$response->getBody()); $this->reportResults(); }