From 4e87f013f027f00c5527fc595f24b766742a072e Mon Sep 17 00:00:00 2001 From: Ere Maijala <ere.maijala@helsinki.fi> Date: Tue, 10 Jul 2018 21:15:35 +0300 Subject: [PATCH] Refactor authority record driver to add non-MARC support (#1215) --- import/marc_auth.properties | 1 + module/VuFind/config/module.config.php | 8 ++- .../src/VuFind/RecordDriver/PluginManager.php | 39 +++++++---- .../{SolrAuth.php => SolrAuthDefault.php} | 22 +------ .../src/VuFind/RecordDriver/SolrAuthMarc.php | 66 +++++++++++++++++++ .../Search/Factory/SolrAuthBackendFactory.php | 7 +- solr/vufind/authority/conf/schema.xml | 2 + .../result-list.phtml | 0 8 files changed, 106 insertions(+), 39 deletions(-) rename module/VuFind/src/VuFind/RecordDriver/{SolrAuth.php => SolrAuthDefault.php} (81%) create mode 100644 module/VuFind/src/VuFind/RecordDriver/SolrAuthMarc.php rename themes/bootstrap3/templates/RecordDriver/{SolrAuth => SolrAuthDefault}/result-list.phtml (100%) diff --git a/import/marc_auth.properties b/import/marc_auth.properties index 30d7b527ea6..e4aadb68f03 100644 --- a/import/marc_auth.properties +++ b/import/marc_auth.properties @@ -4,6 +4,7 @@ # bibliographic settings. # ############################################################################### id = custom, getFirstNormalizedLCCN("010a") +record_format = "marc" lccn = custom, getNormalizedLCCNs("010a") # These values should be overridden in a second properties file (for example, diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index d258c9b20bc..0bc27f60044 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -561,7 +561,13 @@ $config = [ ], 'defaultTab' => null, ], - 'VuFind\RecordDriver\SolrAuth' => [ + 'VuFind\RecordDriver\SolrAuthDefault' => [ + 'tabs' => [ + 'Details' => 'StaffViewArray', + ], + 'defaultTab' => null, + ], + 'VuFind\RecordDriver\SolrAuthMarc' => [ 'tabs' => [ 'Details' => 'StaffViewMARC', ], diff --git a/module/VuFind/src/VuFind/RecordDriver/PluginManager.php b/module/VuFind/src/VuFind/RecordDriver/PluginManager.php index 6c8cc22c134..deb4d000bb7 100644 --- a/module/VuFind/src/VuFind/RecordDriver/PluginManager.php +++ b/module/VuFind/src/VuFind/RecordDriver/PluginManager.php @@ -51,7 +51,9 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager 'missing' => 'VuFind\RecordDriver\Missing', 'pazpar2' => 'VuFind\RecordDriver\Pazpar2', 'primo' => 'VuFind\RecordDriver\Primo', - 'solrauth' => 'VuFind\RecordDriver\SolrAuth', + 'solrauth' => 'VuFind\RecordDriver\SolrAuthMarc', // legacy name + 'solrauthdefault' => 'VuFind\RecordDriver\SolrAuthDefault', + 'solrauthmarc' => 'VuFind\RecordDriver\SolrAuthMarc', 'solrdefault' => 'VuFind\RecordDriver\SolrDefault', 'solrmarc' => 'VuFind\RecordDriver\SolrMarc', 'solrmarcremote' => 'VuFind\RecordDriver\SolrMarcRemote', @@ -89,7 +91,9 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager 'VuFind\RecordDriver\Pazpar2' => 'VuFind\RecordDriver\NameBasedConfigFactory', 'VuFind\RecordDriver\Primo' => 'VuFind\RecordDriver\NameBasedConfigFactory', - 'VuFind\RecordDriver\SolrAuth' => + 'VuFind\RecordDriver\SolrAuthDefault' => + 'VuFind\RecordDriver\SolrDefaultWithoutSearchServiceFactory', + 'VuFind\RecordDriver\SolrAuthMarc' => 'VuFind\RecordDriver\SolrDefaultWithoutSearchServiceFactory', 'VuFind\RecordDriver\SolrDefault' => 'VuFind\RecordDriver\SolrDefaultFactory', @@ -154,22 +158,35 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager /** * Convenience method to retrieve a populated Solr record driver. * - * @param array $data Raw Solr data + * @param array $data Raw Solr data + * @param string $keyPrefix Record class name prefix + * @param string $defaultKeySuffix Default key suffix * * @return AbstractBase */ - public function getSolrRecord($data) - { - if (isset($data['recordtype'])) { - $key = 'Solr' . ucwords($data['recordtype']); - $recordType = $this->has($key) ? $key : 'SolrDefault'; - } else { - $recordType = 'SolrDefault'; - } + public function getSolrRecord($data, $keyPrefix = 'Solr', + $defaultKeySuffix = 'Default' + ) { + $key = $keyPrefix . ucwords( + $data['record_format'] ?? $data['recordtype'] ?? $defaultKeySuffix + ); + $recordType = $this->has($key) ? $key : $keyPrefix . $defaultKeySuffix; // Build the object: $driver = $this->get($recordType); $driver->setRawData($data); return $driver; } + + /** + * Convenience method to retrieve a populated Solr authority record driver. + * + * @param array $data Raw Solr data + * + * @return AbstractBase + */ + public function getSolrAuthRecord($data) + { + return $this->getSolrRecord($data, 'SolrAuth'); + } } diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrAuth.php b/module/VuFind/src/VuFind/RecordDriver/SolrAuthDefault.php similarity index 81% rename from module/VuFind/src/VuFind/RecordDriver/SolrAuth.php rename to module/VuFind/src/VuFind/RecordDriver/SolrAuthDefault.php index e9d89f6e873..412ec121ac1 100644 --- a/module/VuFind/src/VuFind/RecordDriver/SolrAuth.php +++ b/module/VuFind/src/VuFind/RecordDriver/SolrAuthDefault.php @@ -36,7 +36,7 @@ namespace VuFind\RecordDriver; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki */ -class SolrAuth extends SolrMarc +class SolrAuthDefault extends SolrDefault { /** * Get the short (pre-subtitle) title of the record. @@ -82,24 +82,4 @@ class SolrAuth extends SolrMarc && is_array($this->fields['use_for']) ? $this->fields['use_for'] : []; } - - /** - * Get a raw LCCN (not normalized). Returns false if none available. - * - * @return string|bool - */ - public function getRawLCCN() - { - $lccn = $this->getFirstFieldValue('010'); - if (!empty($lccn)) { - return $lccn; - } - $lccns = $this->getFieldArray('700', ['0']); - foreach ($lccns as $lccn) { - if (substr($lccn, 0, '5') == '(DLC)') { - return substr($lccn, 5); - } - } - return false; - } } diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrAuthMarc.php b/module/VuFind/src/VuFind/RecordDriver/SolrAuthMarc.php new file mode 100644 index 00000000000..e8cb8035b25 --- /dev/null +++ b/module/VuFind/src/VuFind/RecordDriver/SolrAuthMarc.php @@ -0,0 +1,66 @@ +<?php +/** + * Model for MARC authority records in Solr. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2010. + * Copyright (C) The National Library of Finland 2015. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package RecordDrivers + * @author Demian Katz <demian.katz@villanova.edu> + * @author Ere Maijala <ere.maijala@helsinki.fi> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki + */ +namespace VuFind\RecordDriver; + +/** + * Model for MARC authority records in Solr. + * + * @category VuFind + * @package RecordDrivers + * @author Demian Katz <demian.katz@villanova.edu> + * @author Ere Maijala <ere.maijala@helsinki.fi> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki + */ +class SolrAuthMarc extends SolrAuthDefault +{ + use MarcReaderTrait; + use MarcAdvancedTrait; + + /** + * Get a raw LCCN (not normalized). Returns false if none available. + * + * @return string|bool + */ + public function getRawLCCN() + { + $lccn = $this->getFirstFieldValue('010'); + if (!empty($lccn)) { + return $lccn; + } + $lccns = $this->getFieldArray('700', ['0']); + foreach ($lccns as $lccn) { + if (substr($lccn, 0, '5') == '(DLC)') { + return substr($lccn, 5); + } + } + return false; + } +} diff --git a/module/VuFind/src/VuFind/Search/Factory/SolrAuthBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/SolrAuthBackendFactory.php index 089c1606ba3..df3086ddba7 100644 --- a/module/VuFind/src/VuFind/Search/Factory/SolrAuthBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/SolrAuthBackendFactory.php @@ -75,12 +75,7 @@ class SolrAuthBackendFactory extends AbstractSolrBackendFactory { $backend = parent::createBackend($connector); $manager = $this->serviceLocator->get('VuFind\RecordDriver\PluginManager'); - $callback = function ($data) use ($manager) { - $driver = $manager->get('SolrAuth'); - $driver->setRawData($data); - return $driver; - }; - $factory = new RecordCollectionFactory($callback); + $factory = new RecordCollectionFactory([$manager, 'getSolrAuthRecord']); $backend->setRecordCollectionFactory($factory); return $backend; } diff --git a/solr/vufind/authority/conf/schema.xml b/solr/vufind/authority/conf/schema.xml index c653c21649b..b5e367662c0 100644 --- a/solr/vufind/authority/conf/schema.xml +++ b/solr/vufind/authority/conf/schema.xml @@ -29,11 +29,13 @@ <field name="fullrecord" type="string" indexed="false" stored="true"/> <field name="marc_error" type="string" indexed="false" stored="true" multiValued="true"/> <field name="allfields" type="text" indexed="true" stored="false" multiValued="true"/> + <field name="record_format" type="string" indexed="true" stored="true"/> <!-- Extra identifiers - where did authority record originate? --> <field name="source" type="string" indexed="true" stored="true"/> <field name="record_type" type="string" indexed="true" stored="true"/> <field name="lccn" type="string" indexed="true" stored="true" multiValued="true"/> + <field name="institution" type="string" indexed="true" stored="true" multiValued="true"/> <!-- String Fields for Exact Match / Faceting --> <field name="heading" type="string" indexed="true" stored="true"/> diff --git a/themes/bootstrap3/templates/RecordDriver/SolrAuth/result-list.phtml b/themes/bootstrap3/templates/RecordDriver/SolrAuthDefault/result-list.phtml similarity index 100% rename from themes/bootstrap3/templates/RecordDriver/SolrAuth/result-list.phtml rename to themes/bootstrap3/templates/RecordDriver/SolrAuthDefault/result-list.phtml -- GitLab