From 80ac2fe51ec9f3f0e824972729b01e96653d2c42 Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Thu, 25 Feb 2016 16:08:10 +0200
Subject: [PATCH] Implemented allowCancelingAvailableRequests setting - Adds
 possibility to disallow canceling of requests that are available for pickup -
 Fixed minor debug-related error

---
 config/vufind/VoyagerRestful.ini              |  3 +++
 .../src/VuFind/Controller/Plugin/Holds.php    |  8 +++++---
 .../src/VuFind/ILS/Driver/VoyagerRestful.php  | 19 ++++++++++++++++---
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/config/vufind/VoyagerRestful.ini b/config/vufind/VoyagerRestful.ini
index 261246515ee..4610a738efc 100644
--- a/config/vufind/VoyagerRestful.ini
+++ b/config/vufind/VoyagerRestful.ini
@@ -174,6 +174,9 @@ disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 ;helpText = "Help text for all languages."
 ;helpText[en-gb] = "Help text for English language."
 
+; By default a request can be canceled even if the item is available for pickup.
+; Uncomment this to disable canceling of available requests.
+;allowCancelingAvailableRequests = false
 
 ; This section controls call slip behavior (storage retrieval requests in VuFind).
 ; To enable, uncomment (at minimum) the HMACKeys and extraFields settings below.
diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Holds.php b/module/VuFind/src/VuFind/Controller/Plugin/Holds.php
index ecb2d1b2d95..1b50dcfb1df 100644
--- a/module/VuFind/src/VuFind/Controller/Plugin/Holds.php
+++ b/module/VuFind/src/VuFind/Controller/Plugin/Holds.php
@@ -60,9 +60,11 @@ class Holds extends AbstractRequestBase
                     = $catalog->getCancelHoldLink($ilsDetails);
             } else {
                 // Form Details
-                $ilsDetails['cancel_details']
-                    = $catalog->getCancelHoldDetails($ilsDetails);
-                $this->rememberValidId($ilsDetails['cancel_details']);
+                $cancelDetails = $catalog->getCancelHoldDetails($ilsDetails);
+                if ($cancelDetails !== '') {
+                    $ilsDetails['cancel_details'] = $cancelDetails;
+                    $this->rememberValidId($ilsDetails['cancel_details']);
+                }
             }
         }
 
diff --git a/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php b/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php
index 4fef5c7e6ce..275f02d5c5b 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php
@@ -207,6 +207,14 @@ class VoyagerRestful extends Voyager implements \VuFindHttp\HttpServiceAwareInte
      */
     protected $excludedItemLocations;
 
+    /**
+     * Whether it is allowed to cancel a request for an item that is available for
+     * pickup
+     *
+     * @var bool
+     */
+    protected $allowCancelingAvailableRequests;
+
     /**
      * Constructor
      *
@@ -295,6 +303,9 @@ class VoyagerRestful extends Voyager implements \VuFindHttp\HttpServiceAwareInte
             = isset($this->config['Holds']['excludedItemLocations'])
             ? str_replace(':', ',', $this->config['Holds']['excludedItemLocations'])
             : '';
+        $this->allowCancelingAvailableRequests
+            = isset($this->config['Holds']['allowCancelingAvailableRequests'])
+            ? $this->config['Holds']['allowCancelingAvailableRequests'] : true;
 
         // Establish a namespace in the session for persisting cached data
         $this->session = new SessionContainer('VoyagerRestful_' . $this->dbName);
@@ -1816,7 +1827,7 @@ EOT;
 
         try {
             $sqlStmt = $this->db->prepare($outersql);
-            $this->debugLogSQL(__FUNCTION__, $outersql, $sql['bind']);
+            $this->debugSQL(__FUNCTION__, $outersql, $sql['bind']);
             $sqlStmt->execute($sql['bind']);
             $sqlRow = $sqlStmt->fetch(PDO::FETCH_ASSOC);
             return $sqlRow['CNT'] > 0;
@@ -2037,8 +2048,10 @@ EOT;
      */
     public function getCancelHoldDetails($holdDetails)
     {
-        $cancelDetails = $holdDetails['item_id'] . "|" . $holdDetails['reqnum'];
-        return $cancelDetails;
+        if (!$this->allowCancelingAvailableRequests && $holdDetails['available']) {
+            return '';
+        }
+        return $holdDetails['item_id'] . '|' . $holdDetails['reqnum'];
     }
 
     /**
-- 
GitLab