diff --git a/module/finc/src/finc/ILS/Connection.php b/module/finc/src/finc/ILS/Connection.php index 2fe8401af447bc639eac7cdc7f73c73ae5ddb913..5ea444a81161d36f980ffe445c349f76e318215d 100644 --- a/module/finc/src/finc/ILS/Connection.php +++ b/module/finc/src/finc/ILS/Connection.php @@ -115,7 +115,6 @@ 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 @@ -172,4 +171,42 @@ class Connection extends \VuFind\ILS\Connection implements TranslatorAwareInterf throw $e; } } + + /** + * Get Offline Mode + * + * This is responsible for returning the offline mode + * + * @param bool $healthCheck Perform a health check in addition to consulting + * the ILS status? + * + * @return string|bool "ils-offline" for systems where the main ILS is offline, + * "ils-none" for systems which do not use an ILS, false for online systems. + * + * @deprecated Backport of VuFind 8.1 (healthCheckId) - remove after upgrade + */ + public function getOfflineMode($healthCheck = false) + { + // If we have NoILS failover configured, force driver initialization so + // we can know we are checking the offline mode against the correct driver. + if ($this->hasNoILSFailover()) { + $this->getDriver(); + } + $hasOfflineMode = $this->checkCapability('getOfflineMode'); + // If we need to perform a health check, try to do a random item lookup + // before proceeding. + if ($healthCheck && $this->config->healthCheckId) { + if (empty($this->getStatus($this->config->healthCheckId)) && $hasOfflineMode) { + // show different return string to separate between basic availability and PAIA later? + return 'ils-offline'; + } + } + + // If we're encountering failures, let's go into ils-offline mode if + // the ILS driver does not natively support getOfflineMode(). + $default = $this->failing ? 'ils-offline' : false; + + // Graceful degradation -- return false if no method supported. + return $hasOfflineMode ? $this->getDriver()->getOfflineMode() : $default; + } } diff --git a/module/finc/src/finc/ILS/Driver/FincILS.php b/module/finc/src/finc/ILS/Driver/FincILS.php index 786db5ce3cc10ed1fafd0ece4d0aab260f45b9a1..169b8f021ea36ac35a464ebea729b2c7368969f4 100644 --- a/module/finc/src/finc/ILS/Driver/FincILS.php +++ b/module/finc/src/finc/ILS/Driver/FincILS.php @@ -261,7 +261,7 @@ class FincILS extends PAIA implements LoggerAwareInterface * systems which do not use an ILS, false for systems that are fully online. If * not implemented, the value defaults to false * - * @return bool + * @return bool|string */ public function getOfflineMode() { @@ -271,7 +271,7 @@ class FincILS extends PAIA implements LoggerAwareInterface return false; } // test again - $this->testILSConnections(); + $this->_testILSConnections(); return false; } catch (\Exception $e) { $this->debug($e->getMessage()); @@ -1697,28 +1697,34 @@ class FincILS extends PAIA implements LoggerAwareInterface } /** - * Private service test method + * Private service test method for basic accessibility of DAIA / PAIA + * + * @param boolean $testDAIA test DAIA service + * @param boolean $testPAIA test PAIA service * * @return void * @throws ILSException */ - private function testILSConnections() + private function _testILSConnections($testDAIA = true, $testPAIA = true) { try { - // test DAIA service - preg_match( - "/^(http[s:\/0-9a-zA-Z\.]*(:[0-9]*)?\/[0-9a-zA-Z\-\/]*)/", - $this->baseUrl, - $daiaMatches - ); - $this->httpService->get($daiaMatches[1], [], $this->ilsTestTimeout); - // test PAIA service - preg_match( - "/^(http[s:\/0-9a-zA-Z\.]*(:[0-9]*)?\/[0-9a-zA-Z\-\/]*)/", - $this->paiaURL, - $paiaMatches - ); - $this->httpService->get($paiaMatches[1], [], $this->ilsTestTimeout); + if ($testDAIA) { + preg_match( + "/^(http[s:\/0-9a-zA-Z\.]*(:[0-9]*)?\/[0-9a-zA-Z\-\/]*)/", + $this->baseUrl, + $daiaMatches + ); + $this->httpService->get($daiaMatches[1], [], $this->ilsTestTimeout); + } + + if ($testPAIA) { + preg_match( + "/^(http[s:\/0-9a-zA-Z\.]*(:[0-9]*)?\/[0-9a-zA-Z\-\/]*)/", + $this->paiaURL, + $paiaMatches + ); + $this->httpService->get($paiaMatches[1], [], $this->ilsTestTimeout); + } // test succeeded, save state $this->isOnline = true;