From f623073a6a0530d76bffebd1869561b0d5a81d4e Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 18 Jul 2012 09:34:19 -0400
Subject: [PATCH] Replaced ugly __call() methods with route configuration to
 achieve the same legacy compatibility effect.

---
 module/VuFind/config/module.config.php        | 20 ++++++++++++++++
 .../src/VuFind/Controller/AbstractRecord.php  |  7 ++++--
 .../VuFind/Controller/SummonController.php    | 23 -------------------
 .../VuFind/Controller/WorldcatController.php  | 23 -------------------
 4 files changed, 25 insertions(+), 48 deletions(-)

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index 2056aa7e94a..71e90cfad7f 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -27,6 +27,26 @@ $config = array(
                         'action'     => 'Show',
                     )
                 )
+            ),
+            'legacy-summonrecord' => array(
+                'type' => 'Zend\Mvc\Router\Http\Literal',
+                'options' => array(
+                    'route'    => '/Summon/Record',
+                    'defaults' => array(
+                        'controller' => 'SummonRecord',
+                        'action'     => 'Home',
+                    )
+                )
+            ),
+            'legacy-worldcatrecord' => array(
+                'type' => 'Zend\Mvc\Router\Http\Literal',
+                'options' => array(
+                    'route'    => '/WorldCat/Record',
+                    'defaults' => array(
+                        'controller' => 'WorldcatRecord',
+                        'action'     => 'Home',
+                    )
+                )
             )
         ),
     ),
diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
index 37fb6359202..f37395f8f78 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
@@ -477,11 +477,14 @@ class AbstractRecord extends AbstractBase
      */
     protected function loadRecord()
     {
-        // Only load the record if it has not already been loaded:
+        // Only load the record if it has not already been loaded.  Note that
+        // when determining record ID, we check both the route match (the most
+        // common scenario) and the GET parameters (a fallback used by some
+        // legacy routes).
         if (!is_object($this->driver)) {
             $this->driver = call_user_func(
                 array($this->searchObject, 'getRecord'),
-                $this->params()->fromRoute('id')
+                $this->params()->fromRoute('id', $this->params()->fromQuery('id'))
             );
         }
         return $this->driver;
diff --git a/module/VuFind/src/VuFind/Controller/SummonController.php b/module/VuFind/src/VuFind/Controller/SummonController.php
index 2e039836b2b..46755025b99 100644
--- a/module/VuFind/src/VuFind/Controller/SummonController.php
+++ b/module/VuFind/src/VuFind/Controller/SummonController.php
@@ -96,29 +96,6 @@ class SummonController extends AbstractSearch
         return $this->resultsAction();
     }
 
-    /**
-     * Forward unrecognized actions to record controller for legacy URL
-     * compatibility.
-     *
-     * @param string $method Method name being called.
-     * @param array  $params Parameters passed to method.
-     *
-     * @return void
-     */
-    public function __call($method, $params)
-    {
-        if (substr($method, -6) == 'Action') {
-            $action = substr($method, 0, strlen($method) - 6);
-            // Special case for default record action:
-            if ($action == 'record') {
-                $action = 'home';
-            }
-            return $this->forward()
-                ->dispatch('SummonRecord', array('action' => $action));
-        }
-        return parent::__call($method, $params);
-    }
-
     /**
      * Return a Search Results object containing advanced facet information.  This
      * data may come from the cache, and it is currently shared between the Home
diff --git a/module/VuFind/src/VuFind/Controller/WorldcatController.php b/module/VuFind/src/VuFind/Controller/WorldcatController.php
index 487a6f4d7f1..4f7a1be0f08 100644
--- a/module/VuFind/src/VuFind/Controller/WorldcatController.php
+++ b/module/VuFind/src/VuFind/Controller/WorldcatController.php
@@ -68,28 +68,5 @@ class WorldcatController extends AbstractSearch
     {
         return $this->resultsAction();
     }
-
-    /**
-     * Forward unrecognized actions to record controller for legacy URL
-     * compatibility.
-     *
-     * @param string $method Method name being called.
-     * @param array  $params Parameters passed to method.
-     *
-     * @return void
-     */
-    public function __call($method, $params)
-    {
-        if (substr($method, -6) == 'Action') {
-            $action = substr($method, 0, strlen($method) - 6);
-            // Special case for default record action:
-            if ($action == 'record') {
-                $action = 'home';
-            }
-            return $this->forward()
-                ->dispatch('WorldcatRecord', array('action' => $action));
-        }
-        return parent::__call($method, $params);
-    }
 }
 
-- 
GitLab