diff --git a/local/config/vufind/FincLibero.ini b/local/config/vufind/FincLibero.ini new file mode 100644 index 0000000000000000000000000000000000000000..26fb4a666a515219f64e3131dccad0fea6de5e75 --- /dev/null +++ b/local/config/vufind/FincLibero.ini @@ -0,0 +1,52 @@ +; General Settings for all FincLibero instances +[Parent_Config] +;inherits FincILS settings from same directory +relative_path=FincILS.ini + +; entries in [RequiredConfig] denote settings that are tested during initialization +; of FincLibero. Syntax is +; <INI Section>[<key within section>] = true for required, false for not required +; e.g. General[departmentLocationBase] = true makes FincLibero::init() +; throw an InitException in case [General]->departmentLocationBase is not set +; in any of FincLibero.ini or FincILS.ini +;[RequiredConfig] +;General[departmentLocationBase] = true +;General[titleHoldLimitations] = true +;General[pickUpLocationPatterns] = true +;General[requestableLimitations] = true +;General[holdableLimitations] = true +;General[recallableLimitations] = true +;General[awlLimitations] = true +;General[stackURIs] = true +;General[readingRoomURIs] = true + +; the following section is here to list info and examples for the settings +; that may be defined as required in [RequiredConfig] +; examples collected in DE-15 and DE-Zwi2 +;[General] +; Pattern that will extend uris for department +;departmentLocationBase = "http://data.ub.uni-leipzig.de/resource/DE-Zwi2/department/zw" + +; Limitations that will trigger an action. +;titleHoldLimitations[] = "DE-Zwi2:OrderTitle:[0-9]+X?" + +; Patterns that will identify limitations as pickUpLocations +;pickUpLocationPatterns[] = "/^http:\/\/data\.ub\.uni-leipzig\.de\/resource\//" + +; Limitations that will trigger the placeStorageRetrievalRequest action +;requestableLimitations[] = DE-15:OrderRequired + +; Limitations that will trigger the placeHold action +;holdableLimitations[] = DE-15:URI + +; Limitations that will trigger a recall action (currently not used). +;recallableLimitations[] = DE-15:ReservationPossible + +; Limitations that will identify the item for being bound to another item. +;awlLimitations[] = DE-15:OrderViaBoundItem + +; URIs that will be used for stack views +;stackURIs[] = "http://data.ub.uni-leipzig.de/resource/DE-15/pickup/zw01thek" + +; URIs that will be used for reading room views +;readingRoomURIs[] = "http://data.ub.uni-leipzig.de/resource/DE-15/pickup/zw01thekfo" diff --git a/module/finc/src/finc/ILS/Connection.php b/module/finc/src/finc/ILS/Connection.php index 8825a66aef1832277416b741b464f5348fec80b7..a7f05faf35fdc579c430ccbc362c746858fe0187 100644 --- a/module/finc/src/finc/ILS/Connection.php +++ b/module/finc/src/finc/ILS/Connection.php @@ -117,4 +117,61 @@ class Connection extends \VuFind\ILS\Connection implements TranslatorAwareInterf return false; } + + /** + * Get access to the driver object. + * Extends parent function with a bypass of failover on InitException + * + * @param bool $init Should we initialize the driver (if necessary), or load it + * "as-is"? + * + * @throws \Exception + * @throws InitException + * @return object + */ + public function getDriver($init = true) + { + if (null === $this->driver) { + $this->setDriver($this->driverManager->get($this->config->driver)); + } + if (!$this->driverInitialized && $init) { + try { + $this->initializeDriver(); + } catch (InitException $e) { + throw $e; + } catch (\Exception $e) { + if (!$this->failOverToNoILS()) { + throw $e; + } + } + } + return $this->driver; + } + + /** + * Get Hidden Login Mode + * + * This is responsible for indicating whether login should be hidden. + * + * Extends parent function with a bypass of failover on InitException + * + * @throws \Exception + * @throws InitException + * @return bool true if the login should be hidden, false if not + */ + public function loginIsHidden() + { + // Graceful degradation -- return false if no method supported. + try { + return $this->checkCapability('loginIsHidden') + ? $this->getDriver()->loginIsHidden() : false; + } catch (InitException $e) { + throw $e; + } catch (\Exception $e) { + if ($this->failOverToNoILS()) { + return call_user_func_array([$this, __METHOD__], func_get_args()); + } + throw $e; + } + } } diff --git a/module/finc/src/finc/ILS/Driver/FincLibero.php b/module/finc/src/finc/ILS/Driver/FincLibero.php index d267750a128ab165ab75e4ba93bb011972cb8be0..91d958f1bf604b53a71c8e72ecc1e3c9763c7219 100644 --- a/module/finc/src/finc/ILS/Driver/FincLibero.php +++ b/module/finc/src/finc/ILS/Driver/FincLibero.php @@ -27,6 +27,7 @@ * @link http://vufind.org/wiki/vufind2:building_an_ils_driver Wiki */ namespace finc\ILS\Driver; +use finc\ILS\InitException; use VuFind\I18n\Translator\TranslatorAwareTrait; use VuFind\I18n\Translator\TranslatorAwareInterface, VuFind\Exception\ILS as ILSException; @@ -122,8 +123,136 @@ class FincLibero extends FincILS implements TranslatorAwareInterface public function init() { parent::init(); - $this->boundItemIdPattern = $this->config['General']['bound_item_id_pattern'] ?? null; - $this->boundItemLabelPattern = $this->config['General']['bound_item_label_pattern'] ?? null; + + $this->setMemberFromConfig('boundItemPattern', 'General', 'bound_item_id_pattern'); + $this->setMemberFromConfig('boundItemLabelPattern', 'General', + 'bound_item_label_pattern'); + + // Get the base URI to extend departments. + $this->setMemberFromConfig( + 'departmentLocationBase', 'General', 'departmentLocationBase', + "No departmentLocationBase defined in FincLibero.ini." + ); + + // get the URIs for the limitations that are marking an item that a hold can + // be placed on + $this->setMemberFromConfig( + 'titleHoldLimitations', + 'General', + 'titleHoldLimitations', + "No Limitations defined for action titleHold.", + 'titleHoldLimitations' + ); + + // get the pickUpLocationPatterns configured in ILS ini and being used for + // filtering limitations used for pickuplocations + $this->setMemberFromConfig( + 'pickUpLocationPatterns', + 'General', + 'pickUpLocationPatterns', + "No pickUpLocationPatterns defined in FincLibero.ini." + ); + + // get the URIs for the limitations that are marking an item that a storage + // retrieval request can be placed on + $this->setMemberFromConfig( + 'requestableLimitations', + 'General', + 'requestableLimitations', + "No Limitations defined for action Storage Retrieval Request.", + 'requestableLimitations' + ); + + // get the URIs for the limitations that are marking an item that a hold can + // be placed on + $this->setMemberFromConfig( + 'holdableLimitations', + 'General', + 'holdableLimitations', + "No Limitations defined for action Hold.", + 'holdableLimitations' + ); + + // get the URIs for the limitations that are marking an item that a recall can + // be placed on + $this->setMemberFromConfig( + 'recallableLimitations', + 'General', + 'recallableLimitations', + "No Limitations defined for action Recall.", + 'recallableLimitations' + ); + + // get URIs of limitations that will identify the item for being bound to + // another item + $this->setMemberFromConfig( + 'awlLimitations', + 'General', + 'awlLimitations', + "No awlLimitations defined.", + 'awlLimitations' + ); + + // get the URIs identifying records for stack views + $this->setMemberFromConfig( + 'stackURIs', + 'General', + 'stackURIs', + "No stack URIs defined." + ); + + // get the URIs identifying records for reading room views + $this->setMemberFromConfig( + 'readingRoomURIs', + 'General', + 'readingRoomURIs', + "No reading room URIs defined." + ); + } + + /** + * Helper function for @see FincLibero::init() + * Set some member variables based on Config entries from FincILS.ini or + * FincLibero.ini. + * If the given config key (in given section) is set, the member variable will be + * initialized with the value(s) from that key. + * Otherwise (not set): + * When the setting is required via the [RequiredConfig] section AND a debug message is + * given, this message will be added to the debug log. + * With the last parameter $configuredLimitationName, the config entry will be added + * to the set of configured limitations under the given name + * + * @param string $memberName name of class member to be set + * @param string $configSection section from INI file to look up (e.g. 'General' for section [General]) + * @param string $configKey config key within that section + * @param string $debugMessage message to add to debug log on fail if the config is set required + * @param string $configuredLimitationName name of limitation type to be used in setConfiguredLimitation() + */ + protected function setMemberFromConfig( + $memberName, + $configSection, + $configKey, + $debugMessage = '', + $configuredLimitationName = '' + ) { + if ( + !isset($this->config[$configSection]) + || + !isset($this->config[$configSection][$configKey]) + ) { + if ( + !empty($debugMessage) + && + ($this->config['RequiredConfig'][$configSection][$configKey] ?? false) + ) { + throw new InitException($debugMessage); + } + } else { + $this->{$memberName} = $this->config[$configSection][$configKey]; + if (!empty($configuredLimitationName)) { + $this->setConfiguredLimitation($configuredLimitationName); + } + } } /** diff --git a/module/finc/src/finc/ILS/InitException.php b/module/finc/src/finc/ILS/InitException.php new file mode 100644 index 0000000000000000000000000000000000000000..7e7a692cc70717ea3e4b107c33806966381ced22 --- /dev/null +++ b/module/finc/src/finc/ILS/InitException.php @@ -0,0 +1,40 @@ +<?php +/** + * Exception thrown in FincLibero::init() + * PHP version 7 + * + * Copyright (C) Leipzig University Library 2021. + * + * 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 ILS_Drivers + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:ils_drivers Wiki + */ +namespace finc\ILS; + +/** + * Exception thrown in FincLibero::init() + * + * @category VuFind + * @package ILS_Drivers + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:ils_drivers Wiki + */ +class InitException extends \Exception +{ +}