From d51e21753a0f302a3759a67931bff964ac93ffda Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 1 Mar 2013 11:29:26 -0500
Subject: [PATCH] Moved validation logic from Voyager driver to Search
 controller -- this should really apply to ALL drivers.

---
 .../src/VuFind/Controller/SearchController.php | 14 ++++++++++++++
 .../VuFind/src/VuFind/ILS/Driver/Voyager.php   | 18 +-----------------
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php
index 9d6ed37f24e..316cb18a696 100644
--- a/module/VuFind/src/VuFind/Controller/SearchController.php
+++ b/module/VuFind/src/VuFind/Controller/SearchController.php
@@ -341,7 +341,21 @@ class SearchController extends AbstractSearch
         $range = $this->params()->fromQuery('range');
         $dept = $this->params()->fromQuery('department');
 
+        // Validate the range parameter -- it should not exceed the greatest
+        // configured value:
         $searchSettings = $this->getConfig('searches');
+        $maxAge = 0;
+        if (isset($searchSettings->NewItem->ranges)) {
+            $tmp = explode(',', $searchSettings->NewItem->ranges);
+            foreach ($tmp as $current) {
+                if (intval($current) > $maxAge) {
+                    $maxAge = intval($current);
+                }
+            }
+        }
+        if ($maxAge > 0 && $range > $maxAge) {
+            $range = $maxAge;
+        }
 
         // The code always pulls in enough catalog results to get a fixed number
         // of pages worth of Solr results.  Note that if the Solr index is out of
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
index a4b70a9dc1d..41f1153df33 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
@@ -27,7 +27,7 @@
  * @link     http://vufind.org/wiki/vufind2:building_an_ils_driver Wiki
  */
 namespace VuFind\ILS\Driver;
-use File_MARC, PDO, PDOException, VuFind\Config\Reader as ConfigReader,
+use File_MARC, PDO, PDOException,
     VuFind\Exception\Date as DateException,
     VuFind\Exception\ILS as ILSException,
     VuFind\I18n\Translator\TranslatorAwareInterface,
@@ -1551,22 +1551,6 @@ class Voyager extends AbstractBase implements TranslatorAwareInterface
     {
         $items = array();
 
-        // Prevent unnecessary load on Voyager -- no point in exceeding the maximum
-        // configured date range.
-        $maxAge = 30;
-        $searchSettings = ConfigReader::getConfig('searches');
-        if (isset($searchSettings->NewItem->ranges)) {
-            $tmp = explode(',', $searchSettings->NewItem->ranges);
-            foreach ($tmp as $current) {
-                if (intval($current) > $maxAge) {
-                    $maxAge = intval($current);
-                }
-            }
-        }
-        if ($daysOld > $maxAge) {
-            $daysOld = $maxAge;
-        }
-
         $bindParams = array(
             ':enddate' => date('d-m-Y', strtotime('now')),
             ':startdate' => date('d-m-Y', strtotime("-$daysOld day"))
-- 
GitLab