Skip to content

Commit

Permalink
Sierra: Add support for harvesting authority records.
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala committed Aug 9, 2024
1 parent 3be8e29 commit 27718ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion conf/datasources.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions src/RecordManager/Base/Harvest/SierraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
}

/**
Expand Down Expand Up @@ -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';
Expand All @@ -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'];
Expand All @@ -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'];
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 27718ba

Please sign in to comment.