From 30ddd7cc01862bd87be9ec86c248e5e1c5b27723 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 13 Sep 2012 15:46:43 -0400 Subject: [PATCH] Replaced \VuFind\Connection\Manager::getCatalogConnection() with service manager factory. --- module/VuFind/config/module.config.php | 7 ++++++ module/VuFind/src/VuFind/Auth/ILS.php | 8 +++---- module/VuFind/src/VuFind/Auth/Manager.php | 17 ++++++++++---- .../VuFind/src/VuFind/Connection/Manager.php | 21 ------------------ .../src/VuFind/Controller/AbstractBase.php | 12 +++++++++- .../src/VuFind/Controller/AjaxController.php | 4 ++-- .../VuFind/Controller/InstallController.php | 2 +- .../Controller/MyResearchController.php | 8 +++---- .../src/VuFind/Controller/Plugin/Reserves.php | 2 +- .../VuFind/Controller/RecordController.php | 2 +- .../VuFind/Controller/SearchController.php | 6 ++--- .../src/VuFind/RecordDriver/SolrMarc.php | 22 ++++++++++++------- .../src/VuFind/Theme/Root/Helper/Ils.php | 4 ++-- .../VuFindConsole/Controller/AbstractBase.php | 10 +++++++++ .../Controller/UtilController.php | 4 ++-- 15 files changed, 75 insertions(+), 54 deletions(-) diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index e5c6587744b..768af74f25c 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -260,6 +260,13 @@ $config = array( ), 'service_manager' => array( 'factories' => array( + 'ilsconnection' => function ($sm) { + $config = \VuFind\Config\Reader::getConfig(); + $catalog = new \VuFind\ILS\Connection(); + $catalog->setServiceLocator($sm); + $catalog->setConfig($config->Catalog); + return $catalog; + }, 'worldcatconnection' => function ($sm) { $wc = new \VuFind\Connection\WorldCat(); $wc->setLogger($sm->get('Logger')); diff --git a/module/VuFind/src/VuFind/Auth/ILS.php b/module/VuFind/src/VuFind/Auth/ILS.php index 4df3e73d00a..4affd198983 100644 --- a/module/VuFind/src/VuFind/Auth/ILS.php +++ b/module/VuFind/src/VuFind/Auth/ILS.php @@ -27,8 +27,7 @@ * @link http://vufind.org/wiki/building_an_authentication_handler Wiki */ namespace VuFind\Auth; -use VuFind\Connection\Manager as ConnectionManager, - VuFind\Exception\Auth as AuthException; +use VuFind\Exception\Auth as AuthException; /** * ILS authentication module. @@ -46,14 +45,15 @@ class ILS extends AbstractBase /** * Get the ILS driver associated with this object (or load the default from - * the connection manager. + * the service manager. * * @return \VuFind\ILS\Driver\DriverInterface */ public function getCatalog() { if (null === $this->catalog) { - $this->catalog = ConnectionManager::connectToCatalog(); + $this->catalog = $this->getServiceLocator()->getServiceLocator() + ->get('ILSConnection'); } return $this->catalog; } diff --git a/module/VuFind/src/VuFind/Auth/Manager.php b/module/VuFind/src/VuFind/Auth/Manager.php index 12d02ea1413..8faef2f7611 100644 --- a/module/VuFind/src/VuFind/Auth/Manager.php +++ b/module/VuFind/src/VuFind/Auth/Manager.php @@ -27,7 +27,6 @@ */ namespace VuFind\Auth; use VuFind\Config\Reader as ConfigReader, - VuFind\Connection\Manager as ConnectionManager, VuFind\Exception\Auth as AuthException, VuFind\Exception\ILS as ILSException, Zend\ServiceManager\ServiceLocatorAwareInterface, Zend\ServiceManager\ServiceLocatorInterface, @@ -65,6 +64,16 @@ class Manager implements ServiceLocatorAwareInterface $this->session = new SessionContainer('Account'); } + /** + * Get the ILS connection. + * + * @return \VuFind\ILS\Connection + */ + protected function getILS() + { + return $this->getServiceLocator()->get('ILSConnection'); + } + /** * Get the authentication handler. * @@ -127,7 +136,7 @@ class Manager implements ServiceLocatorAwareInterface return false; } try { - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); } catch (\Exception $e) { // If we can't connect to the catalog, assume that no special // ILS-related login settings exist -- this prevents ILS errors @@ -281,7 +290,7 @@ class Manager implements ServiceLocatorAwareInterface } try { - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); } catch (ILSException $e) { return false; } @@ -326,7 +335,7 @@ class Manager implements ServiceLocatorAwareInterface public function newCatalogLogin($username, $password) { try { - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); $result = $catalog->patronLogin($username, $password); } catch (ILSException $e) { return false; diff --git a/module/VuFind/src/VuFind/Connection/Manager.php b/module/VuFind/src/VuFind/Connection/Manager.php index 477e1d9afa6..7d149596104 100644 --- a/module/VuFind/src/VuFind/Connection/Manager.php +++ b/module/VuFind/src/VuFind/Connection/Manager.php @@ -55,27 +55,6 @@ class Manager self::$serviceLocator = $serviceLocator; } - /** - * Connect to the catalog. - * - * @return mixed CatalogConnection object on success, boolean false on error - */ - public static function connectToCatalog() - { - // Use a static variable for the connection -- we never want more than one - // connection open at a time, so if we have previously connected, we will - // remember the old connection and return that instead of starting over. - static $catalog = false; - if ($catalog === false) { - $config = ConfigReader::getConfig(); - $catalog = new ILSConnection(); - $catalog->setServiceLocator(self::$serviceLocator); - $catalog->setConfig($config->Catalog); - } - - return $catalog; - } - /** * Connect to the index. * diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php index 0e3cbcbc726..168fc05f862 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractBase.php +++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php @@ -189,12 +189,22 @@ class AbstractBase extends AbstractActionController return $patron; } + /** + * Get the ILS connection. + * + * @return \VuFind\ILS\Connection + */ + public function getILS() + { + return $this->getServiceLocator()->get('ILSConnection'); + } + /** * Get the record loader * * @return \VuFind\Record\Loader */ - protected function getRecordLoader() + public function getRecordLoader() { return $this->getServiceLocator()->get('RecordLoader'); } diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index 67c3d73dbe9..dd14cd2a795 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -183,7 +183,7 @@ class AjaxController extends AbstractBase */ public function getItemStatuses() { - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); $ids = $this->params()->fromQuery('id'); $results = $catalog->getStatuses($ids); @@ -1038,7 +1038,7 @@ class AjaxController extends AbstractBase } try { - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); $patron = $this->getAuthManager()->storedCatalogLogin(); if ($patron) { $results = $catalog->checkRequestIsValid($id, $data, $patron); diff --git a/module/VuFind/src/VuFind/Controller/InstallController.php b/module/VuFind/src/VuFind/Controller/InstallController.php index f82b77573f1..a04d980bdfe 100644 --- a/module/VuFind/src/VuFind/Controller/InstallController.php +++ b/module/VuFind/src/VuFind/Controller/InstallController.php @@ -379,7 +379,7 @@ class InstallController extends AbstractBase $status = false; } else { try { - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); $catalog->getStatus('1'); $status = true; } catch (\Exception $e) { diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index 6464876b4dc..497ddda21b9 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -234,7 +234,7 @@ class MyResearchController extends AbstractBase $view = $this->createViewModel(); // Obtain user information from ILS: - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); $profile = $catalog->getMyProfile($patron); $profile['home_library'] = $user->home_library; $view->profile = $profile; @@ -758,7 +758,7 @@ class MyResearchController extends AbstractBase } // Connect to the ILS: - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); // Process cancel requests if necessary: $cancelStatus = $catalog->checkFunction('cancelHolds'); @@ -808,7 +808,7 @@ class MyResearchController extends AbstractBase } // Connect to the ILS: - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); // Get the current renewal status and process renewal form, if necessary: $renewStatus = $catalog->checkFunction('Renewals'); @@ -861,7 +861,7 @@ class MyResearchController extends AbstractBase } // Connect to the ILS: - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); // Get fine details: $result = $catalog->getMyFines($patron); diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Reserves.php b/module/VuFind/src/VuFind/Controller/Plugin/Reserves.php index 708911fa155..b64ad16a068 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/Reserves.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/Reserves.php @@ -87,7 +87,7 @@ class Reserves extends AbstractPlugin } // Default case -- find reserves info from the catalog - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getController()->getILS(); return $catalog->findReserves($course, $inst, $dept); } } \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Controller/RecordController.php b/module/VuFind/src/VuFind/Controller/RecordController.php index 8fb6b876a11..a022b505903 100644 --- a/module/VuFind/src/VuFind/Controller/RecordController.php +++ b/module/VuFind/src/VuFind/Controller/RecordController.php @@ -74,7 +74,7 @@ class RecordController extends AbstractRecord public function holdAction() { // If we're not supposed to be here, give up now! - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); $checkHolds = $catalog->checkFunction("Holds"); if (!$checkHolds) { return $this->forwardTo('Record', 'Home'); diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php index 4374a4eb224..d38b92aabfd 100644 --- a/module/VuFind/src/VuFind/Controller/SearchController.php +++ b/module/VuFind/src/VuFind/Controller/SearchController.php @@ -312,7 +312,7 @@ class SearchController extends AbstractSearch $ranges = array(1, 5, 30); } - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); return $this->createViewModel( array('fundList' => $catalog->getFunds(), 'ranges' => $ranges) ); @@ -342,7 +342,7 @@ class SearchController extends AbstractSearch } else { $resultPages = 10; } - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); $sm = $this->getSearchManager(); $params = $sm->setSearchClassId('Solr')->getParams(); $perPage = $params->getLimit(); @@ -414,7 +414,7 @@ class SearchController extends AbstractSearch // If we got this far, we're using driver-based searching and need to // send options to the view: - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); return $this->createViewModel( array( 'deptList' => $catalog->getDepartments(), diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php index ff4d19025fd..2a20ad712ef 100644 --- a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php +++ b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php @@ -790,6 +790,16 @@ class SolrMarc extends SolrDefault return parent::getXML($format); } + /** + * Get the ILS connection. + * + * @return \VuFind\ILS\Connection + */ + protected function getILS() + { + return $this->getServiceLocator()->getServiceLocator()->get('ILSConnection'); + } + /** * Get an array of information about record holdings, obtained in real-time * from the ILS. @@ -800,7 +810,7 @@ class SolrMarc extends SolrDefault */ public function getRealTimeHoldings($account) { - $holdLogic = new HoldLogic($account, ConnectionManager::connectToCatalog()); + $holdLogic = new HoldLogic($account, $this->getILS()); return $holdLogic->getHoldings($this->getUniqueID()); } @@ -814,9 +824,7 @@ class SolrMarc extends SolrDefault { // Get Acquisitions Data try { - return ConnectionManager::connectToCatalog()->getPurchaseHistory( - $this->getUniqueID() - ); + return $this->getILS()->getPurchaseHistory($this->getUniqueID()); } catch (ILSException $e) { return array(); } @@ -836,9 +844,7 @@ class SolrMarc extends SolrDefault || stristr("part", $biblioLevel) ) { if (ILSConnection::getTitleHoldsMode() != "disabled") { - $holdLogic = new TitleHoldLogic( - $account, ConnectionManager::connectToCatalog() - ); + $holdLogic = new TitleHoldLogic($account, $this->getILS()); return $holdLogic->getHold($this->getUniqueID()); } } @@ -861,7 +867,7 @@ class SolrMarc extends SolrDefault if (isset($config->Site->hideHoldingsTabWhenEmpty) && $config->Site->hideHoldingsTabWhenEmpty ) { - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); if (!$catalog->hasHoldings($this->getUniqueID())) { unset($tabs['Holdings']); } diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/Ils.php b/module/VuFind/src/VuFind/Theme/Root/Helper/Ils.php index fccfccf7283..ed99d11de65 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/Ils.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/Ils.php @@ -37,7 +37,7 @@ use Zend\View\Helper\AbstractHelper; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -class Ils extends AbstractHelper +class Ils extends AbstractServiceLocator { /** * Get the ILS connection object. @@ -46,6 +46,6 @@ class Ils extends AbstractHelper */ public function __invoke() { - return \VuFind\Connection\Manager::connectToCatalog(); + return $this->getServiceLocator()->get('ILSConnection'); } } \ No newline at end of file diff --git a/module/VuFindConsole/src/VuFindConsole/Controller/AbstractBase.php b/module/VuFindConsole/src/VuFindConsole/Controller/AbstractBase.php index e2881c92b15..1a23b0988ac 100644 --- a/module/VuFindConsole/src/VuFindConsole/Controller/AbstractBase.php +++ b/module/VuFindConsole/src/VuFindConsole/Controller/AbstractBase.php @@ -100,6 +100,16 @@ class AbstractBase extends AbstractActionController return $this->getResponse()->setErrorLevel(0); } + /** + * Get the ILS connection. + * + * @return \VuFind\ILS\Connection + */ + public function getILS() + { + return $this->getServiceLocator()->get('ILSConnection'); + } + /** * Get a database table object. * diff --git a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php index 557eee846d2..2967cbaefbf 100644 --- a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php +++ b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php @@ -54,7 +54,7 @@ class UtilController extends AbstractBase $solr = ConnectionManager::connectToIndex('SolrReserves'); // Connect to ILS - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); // Records to index $index = array(); @@ -268,7 +268,7 @@ class UtilController extends AbstractBase // Make ILS Connection try { - $catalog = ConnectionManager::connectToCatalog(); + $catalog = $this->getILS(); if ($core == 'authority') { $result = $catalog->getSuppressedAuthorityRecords(); } else { -- GitLab