From 82a5eba484a6e3d0fa4c3e4659aaa62c9ac6d559 Mon Sep 17 00:00:00 2001 From: tubia <tubia@users.noreply.github.com> Date: Fri, 8 Jul 2016 08:19:09 -0400 Subject: [PATCH] Added Solr id prefix setting to NoILS driver. - This applies when NoILS is used in combo with MultiBackend. --- config/vufind/NoILS.ini | 5 +++++ module/VuFind/src/VuFind/ILS/Driver/NoILS.php | 22 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/config/vufind/NoILS.ini b/config/vufind/NoILS.ini index f76ae81a88d..25a793100b8 100644 --- a/config/vufind/NoILS.ini +++ b/config/vufind/NoILS.ini @@ -14,6 +14,11 @@ useHoldings = none ; marc = Use information in the Marc Record Mapped from [MarcStatus] ; custom = use the options in the [Status] section below useStatus = none +;idPrefix - Optional - Prefix added to Solr record IDs managed by this instance of +; the NoILS driver; needed when using this driver in combination with the +; MultiBackend driver. When used, the value should usually match one of the keys +; in the [Drivers] section of MultiBackend.ini followed by a dot. +;idPrefix = "instance1." [MarcHoldings] ; Used if useHoldings is set to "marc" diff --git a/module/VuFind/src/VuFind/ILS/Driver/NoILS.php b/module/VuFind/src/VuFind/ILS/Driver/NoILS.php index c72dc3923d9..b34b62222ac 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/NoILS.php +++ b/module/VuFind/src/VuFind/ILS/Driver/NoILS.php @@ -91,6 +91,17 @@ class NoILS extends AbstractBase implements TranslatorAwareInterface return isset($this->config[$function]) ? $this->config[$function] : false; } + /** + * Get the ID prefix from the configuration, if set. + * + * @return string + */ + protected function getIdPrefix() + { + return isset($this->config['settings']['idPrefix']) + ? $this->config['settings']['idPrefix'] : null; + } + /** * Get a Solr record. * @@ -100,7 +111,9 @@ class NoILS extends AbstractBase implements TranslatorAwareInterface */ protected function getSolrRecord($id) { - return $this->recordLoader->load($id); + // Add idPrefix condition + $idPrefix = $this->getIdPrefix(); + return $this->recordLoader->load(strlen($idPrefix) ? $idPrefix . $id : $id); } /** @@ -246,6 +259,13 @@ class NoILS extends AbstractBase implements TranslatorAwareInterface $result = $recordDriver->tryMethod( 'getFormattedMarcDetails', [$field, $marcStatus] ); + // If the details coming back from the record driver include the + // ID prefix, strip it off! + $idPrefix = $this->getIdPrefix(); + if (isset($result[0]['id']) && strlen($idPrefix) + && $idPrefix === substr($result[0]['id'], 0, strlen($idPrefix))) { + $result[0]['id'] = substr($result[0]['id'], strlen($idPrefix)); + } return empty($result) ? [] : $result; } return []; -- GitLab