From 72312eaa627d6ee737674f1c06169ecacae0ead0 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 7 Aug 2014 13:50:05 -0400
Subject: [PATCH] Configurable port number for Primo connector. - Resolves
 VUFIND-1013.

---
 config/vufind/Primo.ini                                     | 6 +++++-
 .../src/VuFind/Search/Factory/PrimoBackendFactory.php       | 6 ++++--
 .../src/VuFindSearch/Backend/Primo/Connector.php            | 5 +++--
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/config/vufind/Primo.ini b/config/vufind/Primo.ini
index 48a9fefe090..afd0d6dfa2c 100644
--- a/config/vufind/Primo.ini
+++ b/config/vufind/Primo.ini
@@ -15,9 +15,13 @@ case_sensitive_bools = true
 ; HTTP timeout
 timeout = 30
 
-; Your API id
+; Your API id (use "mlplus" if using Metalib Plus instead of Primo Central)
 apiId = my-id
 
+; The port to use when connecting to the API (normally 1701 for Primo Central, 80
+; for Metalib Plus)
+port = 1701
+
 ; This section controls the result limit options for search results. default_limit
 ; sets the default number of results per page. limit_options is a comma-separated
 ; list of numbers to be presented to the end-user. If only one limit is required,
diff --git a/module/VuFind/src/VuFind/Search/Factory/PrimoBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/PrimoBackendFactory.php
index 254dcbac627..ea093a61276 100644
--- a/module/VuFind/src/VuFind/Search/Factory/PrimoBackendFactory.php
+++ b/module/VuFind/src/VuFind/Search/Factory/PrimoBackendFactory.php
@@ -112,9 +112,11 @@ class PrimoBackendFactory implements FactoryInterface
      */
     protected function createConnector()
     {
-        // Load credentials:
+        // Load credentials and port number:
         $id = isset($this->primoConfig->General->apiId)
             ? $this->primoConfig->General->apiId : null;
+        $port = isset($this->primoConfig->General->port)
+            ? $this->primoConfig->General->port : 1701;
 
         // Build HTTP client:
         $client = $this->serviceLocator->get('VuFind\Http')->createClient();
@@ -122,7 +124,7 @@ class PrimoBackendFactory implements FactoryInterface
             ? $this->primoConfig->General->timeout : 30;
         $client->setOptions(array('timeout' => $timeout));
 
-        $connector = new Connector($id, $this->getInstCode(), $client);
+        $connector = new Connector($id, $this->getInstCode(), $client, $port);
         $connector->setLogger($this->logger);
         return $connector;
     }
diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php
index 85828c5f3e9..f9da00967f8 100644
--- a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php
+++ b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php
@@ -90,10 +90,11 @@ class Connector
      * @param string     $apiId  Primo API ID
      * @param string     $inst   Institution code
      * @param HttpClient $client HTTP client
+     * @param int        $port   API connection port
      */
-    public function __construct($apiId, $inst, $client)
+    public function __construct($apiId, $inst, $client, $port = 1701)
     {
-        $this->host = "http://$apiId.hosted.exlibrisgroup.com:1701/"
+        $this->host = "http://$apiId.hosted.exlibrisgroup.com:{$port}/"
             . "PrimoWebServices/xservice/search/brief?";
         $this->inst = $inst;
         $this->client = $client;
-- 
GitLab