From d68a865a6037944fbea91b54a325d43780949a12 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 31 Aug 2012 10:28:32 -0400
Subject: [PATCH] Made constructor injection of catalog connection into ILS
 logic classes mandatory to break unnecessary dependencies.

---
 module/VuFind/src/VuFind/Controller/AjaxController.php | 10 ++++++----
 module/VuFind/src/VuFind/ILS/Logic/Holds.php           |  6 ++----
 module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php      |  6 ++----
 module/VuFind/src/VuFind/RecordDriver/SolrMarc.php     |  6 ++++--
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php
index 62ed914957f..fe9a13d3316 100644
--- a/module/VuFind/src/VuFind/Controller/AjaxController.php
+++ b/module/VuFind/src/VuFind/Controller/AjaxController.php
@@ -149,15 +149,17 @@ class AjaxController extends AbstractBase
      * Support method for getItemStatuses() -- filter suppressed locations from the
      * array of item information for a particular bib record.
      *
-     * @param array $record Information on items linked to a single bib record
+     * @param array                  $record  Information on items linked to a single
+     * bib record
+     * @param \VuFind\ILS\Connection $catalog ILS connection
      *
      * @return array        Filtered version of $record
      */
-    protected function filterSuppressedLocations($record)
+    protected function filterSuppressedLocations($record, $catalog)
     {
         static $hideHoldings = false;
         if ($hideHoldings === false) {
-            $logic = new \VuFind\ILS\Logic\Holds($this->getAuthManager());
+            $logic = new \VuFind\ILS\Logic\Holds($this->getAuthManager(), $catalog);
             $hideHoldings = $logic->getSuppressedLocations();
         }
 
@@ -221,7 +223,7 @@ class AjaxController extends AbstractBase
         $statuses = array();
         foreach ($results as $recordNumber=>$record) {
             // Filter out suppressed locations:
-            $record = $this->filterSuppressedLocations($record);
+            $record = $this->filterSuppressedLocations($record, $catalog);
 
             // Skip empty records:
             if (count($record)) {
diff --git a/module/VuFind/src/VuFind/ILS/Logic/Holds.php b/module/VuFind/src/VuFind/ILS/Logic/Holds.php
index b7c44d5dfc7..543ba0180f7 100644
--- a/module/VuFind/src/VuFind/ILS/Logic/Holds.php
+++ b/module/VuFind/src/VuFind/ILS/Logic/Holds.php
@@ -28,7 +28,6 @@
  */
 namespace VuFind\ILS\Logic;
 use VuFind\Config\Reader as ConfigReader,
-    VuFind\Connection\Manager as ConnectionManager,
     VuFind\Crypt\HMAC,
     VuFind\ILS\Connection as ILSConnection;
 
@@ -55,7 +54,7 @@ class Holds
      * @param \VuFind\Auth\Manager $account Auth manager object
      * @param ILSConnection        $catalog A catalog connection
      */
-    public function __construct($account, $catalog = false)
+    public function __construct($account, $catalog)
     {
         $this->account = $account;
         $this->config = ConfigReader::getConfig();
@@ -66,8 +65,7 @@ class Holds
             }
         }
 
-        $this->catalog = ($catalog !== false)
-            ? $catalog : ConnectionManager::connectToCatalog();
+        $this->catalog = $catalog;
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php b/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php
index 7e80187635f..103ccc2e0ac 100644
--- a/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php
+++ b/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php
@@ -28,7 +28,6 @@
  */
 namespace VuFind\ILS\Logic;
 use VuFind\Config\Reader as ConfigReader,
-    VuFind\Connection\Manager as ConnectionManager,
     VuFind\Crypt\HMAC,
     VuFind\ILS\Connection as ILSConnection;
 
@@ -55,7 +54,7 @@ class TitleHolds
      * @param \VuFind\Auth\Manager $account Auth manager object
      * @param ILSConnection        $catalog A catalog connection
      */
-    public function __construct($account, $catalog = false)
+    public function __construct($account, $catalog)
     {
         $this->account = $account;
         $this->config = ConfigReader::getConfig();
@@ -66,8 +65,7 @@ class TitleHolds
             }
         }
 
-        $this->catalog = ($catalog !== false)
-            ? $catalog : ConnectionManager::connectToCatalog();
+        $this->catalog = $catalog;
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
index a0ea58cb5b5..c3151ebb0aa 100644
--- a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
+++ b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
@@ -797,7 +797,7 @@ class SolrMarc extends SolrDefault
      */
     public function getRealTimeHoldings($account)
     {
-        $holdLogic = new HoldLogic($account);
+        $holdLogic = new HoldLogic($account, ConnectionManager::connectToCatalog());
         return $holdLogic->getHoldings($this->getUniqueID());
     }
 
@@ -833,7 +833,9 @@ class SolrMarc extends SolrDefault
             || stristr("part", $biblioLevel)
         ) {
             if (ILSConnection::getTitleHoldsMode() != "disabled") {
-                $holdLogic = new TitleHoldLogic($account);
+                $holdLogic = new TitleHoldLogic(
+                    $account, ConnectionManager::connectToCatalog()
+                );
                 return $holdLogic->getHold($this->getUniqueID());
             }
         }
-- 
GitLab