From 90f1c541a9c09ef652f87e692935ad77c20a5593 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 3 Dec 2015 09:48:59 -0500 Subject: [PATCH] Introduce "default search backend" constant. - First step in "VuFind" source cleanup; see VUFIND-1139. --- module/VuDL/src/VuDL/Controller/VudlController.php | 2 +- .../src/VuFind/Controller/AjaxController.php | 10 +++++----- .../src/VuFind/Controller/MyResearchController.php | 14 +++++++++----- module/VuFind/src/VuFind/Db/Row/User.php | 14 ++++++++------ module/VuFind/src/VuFind/Db/Row/UserList.php | 5 +++-- module/VuFind/src/VuFind/Db/Table/Comments.php | 2 +- module/VuFind/src/VuFind/Db/Table/Resource.php | 6 +++--- module/VuFind/src/VuFind/Db/Table/Tags.php | 2 +- module/VuFind/src/VuFind/Db/Table/UserList.php | 4 ++-- module/VuFind/src/VuFind/Db/Table/UserResource.php | 4 ++-- module/VuFind/src/VuFind/ILS/Driver/Demo.php | 2 +- module/VuFind/src/VuFind/ILS/Logic/Holds.php | 3 ++- module/VuFind/src/VuFind/Record/Loader.php | 7 ++++--- module/VuFind/src/VuFind/Record/Router.php | 4 ++-- .../VuFind/src/VuFind/View/Helper/Root/Record.php | 8 ++++---- .../src/VuFind/View/Helper/Root/RecordLink.php | 3 ++- public/index.php | 3 +++ 17 files changed, 53 insertions(+), 40 deletions(-) diff --git a/module/VuDL/src/VuDL/Controller/VudlController.php b/module/VuDL/src/VuDL/Controller/VudlController.php index a27897385e6..daa5cc407ad 100644 --- a/module/VuDL/src/VuDL/Controller/VudlController.php +++ b/module/VuDL/src/VuDL/Controller/VudlController.php @@ -252,7 +252,7 @@ class VudlController extends AbstractVuDL $view->id = $root; try { - $driver = $this->getRecordLoader()->load($root, 'VuFind'); + $driver = $this->getRecordLoader()->load($root); } catch(\Exception $e) { } if (isset($driver) && $driver->isProtected()) { diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index d8ccc7db0f6..d48f3c2b1b7 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -490,7 +490,7 @@ class AjaxController extends AbstractBase ); } foreach ($ids as $i => $id) { - $source = isset($sources[$i]) ? $sources[$i] : 'VuFind'; + $source = isset($sources[$i]) ? $sources[$i] : DEFAULT_SEARCH_BACKEND; $data = $user->getSavedData($id, null, $source); if ($data) { // if this item was saved, add it to the list of saved items. @@ -634,7 +634,7 @@ class AjaxController extends AbstractBase try { $driver = $this->getRecordLoader()->load( $this->params()->fromPost('id'), - $this->params()->fromPost('source', 'VuFind') + $this->params()->fromPost('source', DEFAULT_SEARCH_BACKEND) ); $tag = $this->params()->fromPost('tag', ''); $tagParser = $this->getServiceLocator()->get('VuFind\Tags'); @@ -668,7 +668,7 @@ class AjaxController extends AbstractBase $tagTable = $this->getTable('Tags'); $tags = $tagTable->getForResource( $this->params()->fromQuery('id'), - $this->params()->fromQuery('source', 'VuFind'), + $this->params()->fromQuery('source', DEFAULT_SEARCH_BACKEND), 0, null, null, 'count', $is_me_id ); @@ -977,7 +977,7 @@ class AjaxController extends AbstractBase $table = $this->getTable('Resource'); $resource = $table->findResource( - $id, $this->params()->fromPost('source', 'VuFind') + $id, $this->params()->fromPost('source', DEFAULT_SEARCH_BACKEND) ); $id = $resource->addComment($comment, $user); @@ -1019,7 +1019,7 @@ class AjaxController extends AbstractBase { $driver = $this->getRecordLoader()->load( $this->params()->fromQuery('id'), - $this->params()->fromQuery('source', 'VuFind') + $this->params()->fromQuery('source', DEFAULT_SEARCH_BACKEND) ); $html = $this->getViewRenderer() ->render('record/comments-list.phtml', ['driver' => $driver]); diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index 0ab2057c642..a8e76e47bfc 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -535,7 +535,7 @@ class MyResearchController extends AbstractBase // Get current record (and, if applicable, selected list ID) for convenience: $id = $this->params()->fromPost('id', $this->params()->fromQuery('id')); $source = $this->params()->fromPost( - 'source', $this->params()->fromQuery('source', 'VuFind') + 'source', $this->params()->fromQuery('source', DEFAULT_SEARCH_BACKEND) ); $driver = $this->getRecordLoader()->load($id, $source, true); $listID = $this->params()->fromPost( @@ -629,7 +629,8 @@ class MyResearchController extends AbstractBase ); if ($deleteId) { $deleteSource = $this->params()->fromPost( - 'source', $this->params()->fromQuery('source', 'VuFind') + 'source', + $this->params()->fromQuery('source', DEFAULT_SEARCH_BACKEND) ); // If the user already confirmed the operation, perform the delete now; // otherwise prompt for confirmation: @@ -699,7 +700,8 @@ class MyResearchController extends AbstractBase // to the save screen; otherwise, send them back to the list they // just edited. $recordId = $this->params()->fromQuery('recordId'); - $recordSource = $this->params()->fromQuery('recordSource', 'VuFind'); + $recordSource + = $this->params()->fromQuery('recordSource', DEFAULT_SEARCH_BACKEND); if (!empty($recordId)) { $details = $this->getRecordRouter()->getActionRouteDetails( $recordSource . '|' . $recordId, 'Save' @@ -845,7 +847,8 @@ class MyResearchController extends AbstractBase protected function getDriverForILSRecord($current) { $id = isset($current['id']) ? $current['id'] : null; - $source = isset($current['source']) ? $current['source'] : 'VuFind'; + $source = isset($current['source']) + ? $current['source'] : DEFAULT_SEARCH_BACKEND; $record = $this->getServiceLocator()->get('VuFind\RecordLoader') ->load($id, $source, true); $record->setExtraDetail('ils_details', $current); @@ -1135,7 +1138,8 @@ class MyResearchController extends AbstractBase if (!isset($row['id']) || empty($row['id'])) { throw new \Exception(); } - $source = isset($row['source']) ? $row['source'] : 'VuFind'; + $source = isset($row['source']) + ? $row['source'] : DEFAULT_SEARCH_BACKEND; $row['driver'] = $this->getServiceLocator() ->get('VuFind\RecordLoader')->load($row['id'], $source); $row['title'] = $row['driver']->getShortTitle(); diff --git a/module/VuFind/src/VuFind/Db/Row/User.php b/module/VuFind/src/VuFind/Db/Row/User.php index 2a7ee2cc86c..f31441a3e64 100644 --- a/module/VuFind/src/VuFind/Db/Row/User.php +++ b/module/VuFind/src/VuFind/Db/Row/User.php @@ -223,8 +223,9 @@ class User extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface, * * @return \Zend\Db\ResultSet\AbstractResultSet */ - public function getTags($resourceId = null, $listId = null, $source = 'VuFind') - { + public function getTags($resourceId = null, $listId = null, + $source = DEFAULT_SEARCH_BACKEND + ) { $userId = $this->id; $callback = function ($select) use ($userId, $resourceId, $listId, $source) { $select->columns( @@ -285,7 +286,7 @@ class User extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface, * @return string */ public function getTagString($resourceId = null, $listId = null, - $source = 'VuFind' + $source = DEFAULT_SEARCH_BACKEND ) { $myTagList = $this->getTags($resourceId, $listId, $source); $tagStr = ''; @@ -347,8 +348,9 @@ class User extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface, * * @return array */ - public function getSavedData($resourceId, $listId = null, $source = 'VuFind') - { + public function getSavedData($resourceId, $listId = null, + $source = DEFAULT_SEARCH_BACKEND + ) { $table = $this->getDbTable('UserResource'); return $table->getSavedData($resourceId, $source, $listId, $this->id); } @@ -395,7 +397,7 @@ class User extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface, * * @return void */ - public function removeResourcesById($ids, $source = 'VuFind') + public function removeResourcesById($ids, $source = DEFAULT_SEARCH_BACKEND) { // Retrieve a list of resource IDs: $resourceTable = $this->getDbTable('Resource'); diff --git a/module/VuFind/src/VuFind/Db/Row/UserList.php b/module/VuFind/src/VuFind/Db/Row/UserList.php index e44be974069..931740a24a5 100644 --- a/module/VuFind/src/VuFind/Db/Row/UserList.php +++ b/module/VuFind/src/VuFind/Db/Row/UserList.php @@ -162,8 +162,9 @@ class UserList extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterf * * @return void */ - public function removeResourcesById($user, $ids, $source = 'VuFind') - { + public function removeResourcesById($user, $ids, + $source = DEFAULT_SEARCH_BACKEND + ) { if (!$this->editAllowed($user)) { throw new ListPermissionException('list_access_denied'); } diff --git a/module/VuFind/src/VuFind/Db/Table/Comments.php b/module/VuFind/src/VuFind/Db/Table/Comments.php index 01bafd3ef3a..21ecd16f70a 100644 --- a/module/VuFind/src/VuFind/Db/Table/Comments.php +++ b/module/VuFind/src/VuFind/Db/Table/Comments.php @@ -55,7 +55,7 @@ class Comments extends Gateway * * @return array|\Zend\Db\ResultSet\AbstractResultSet */ - public function getForResource($id, $source = 'VuFind') + public function getForResource($id, $source = DEFAULT_SEARCH_BACKEND) { $resourceTable = $this->getDbTable('Resource'); $resource = $resourceTable->findResource($id, $source, false); diff --git a/module/VuFind/src/VuFind/Db/Table/Resource.php b/module/VuFind/src/VuFind/Db/Table/Resource.php index 91ae95ca661..cb8ca06fd07 100644 --- a/module/VuFind/src/VuFind/Db/Table/Resource.php +++ b/module/VuFind/src/VuFind/Db/Table/Resource.php @@ -72,8 +72,8 @@ class Resource extends Gateway * @return \VuFind\Db\Row\Resource|null Matching row if found or created, null * otherwise. */ - public function findResource($id, $source = 'VuFind', $create = true, - $driver = null + public function findResource($id, $source = DEFAULT_SEARCH_BACKEND, + $create = true, $driver = null ) { if (empty($id)) { throw new \Exception('Resource ID cannot be empty'); @@ -110,7 +110,7 @@ class Resource extends Gateway * * @return \Zend\Db\ResultSet\AbstractResultSet */ - public function findResources($ids, $source = 'VuFind') + public function findResources($ids, $source = DEFAULT_SEARCH_BACKEND) { $callback = function ($select) use ($ids, $source) { $select->where->in('record_id', $ids); diff --git a/module/VuFind/src/VuFind/Db/Table/Tags.php b/module/VuFind/src/VuFind/Db/Table/Tags.php index 1884a8b680b..641286c0139 100644 --- a/module/VuFind/src/VuFind/Db/Table/Tags.php +++ b/module/VuFind/src/VuFind/Db/Table/Tags.php @@ -100,7 +100,7 @@ class Tags extends Gateway * * @return array */ - public function getForResource($id, $source = 'VuFind', $limit = 0, + public function getForResource($id, $source = DEFAULT_SEARCH_BACKEND, $limit = 0, $list = null, $user = null, $sort = 'count', $userToCheck = null ) { return $this->select( diff --git a/module/VuFind/src/VuFind/Db/Table/UserList.php b/module/VuFind/src/VuFind/Db/Table/UserList.php index 9791950cf79..0665fa6597a 100644 --- a/module/VuFind/src/VuFind/Db/Table/UserList.php +++ b/module/VuFind/src/VuFind/Db/Table/UserList.php @@ -97,8 +97,8 @@ class UserList extends Gateway * * @return array */ - public function getListsContainingResource($resourceId, $source = 'VuFind', - $userId = null + public function getListsContainingResource($resourceId, + $source = DEFAULT_SEARCH_BACKEND, $userId = null ) { // Set up base query: $callback = function ($select) use ($resourceId, $source, $userId) { diff --git a/module/VuFind/src/VuFind/Db/Table/UserResource.php b/module/VuFind/src/VuFind/Db/Table/UserResource.php index 182b7cefa6e..e19cc194cf3 100644 --- a/module/VuFind/src/VuFind/Db/Table/UserResource.php +++ b/module/VuFind/src/VuFind/Db/Table/UserResource.php @@ -59,8 +59,8 @@ class UserResource extends Gateway * * @return \Zend\Db\ResultSet\AbstractResultSet */ - public function getSavedData($resourceId, $source = 'VuFind', $listId = null, - $userId = null + public function getSavedData($resourceId, $source = DEFAULT_SEARCH_BACKEND, + $listId = null, $userId = null ) { $callback = function ($select) use ($resourceId, $source, $listId, $userId) { $select->columns( diff --git a/module/VuFind/src/VuFind/ILS/Driver/Demo.php b/module/VuFind/src/VuFind/ILS/Driver/Demo.php index c6219f89752..9bb41562836 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Demo.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Demo.php @@ -213,7 +213,7 @@ class Demo extends AbstractBase protected function getRecordSource() { return isset($this->config['Records']['source']) - ? $this->config['Records']['source'] : 'VuFind'; + ? $this->config['Records']['source'] : DEFAULT_SEARCH_BACKEND; } /** diff --git a/module/VuFind/src/VuFind/ILS/Logic/Holds.php b/module/VuFind/src/VuFind/ILS/Logic/Holds.php index 6673cd550c1..7c6c02d8eba 100644 --- a/module/VuFind/src/VuFind/ILS/Logic/Holds.php +++ b/module/VuFind/src/VuFind/ILS/Logic/Holds.php @@ -490,7 +490,8 @@ class Holds // Build Params return [ 'action' => $action, 'record' => $details['id'], - 'source' => isset($details['source']) ? $details['source'] : 'VuFind', + 'source' => isset($details['source']) + ? $details['source'] : DEFAULT_SEARCH_BACKEND, 'query' => $queryString, 'anchor' => "#tabnav" ]; } diff --git a/module/VuFind/src/VuFind/Record/Loader.php b/module/VuFind/src/VuFind/Record/Loader.php index 6ca7e4653ee..ad1059ac4a4 100644 --- a/module/VuFind/src/VuFind/Record/Loader.php +++ b/module/VuFind/src/VuFind/Record/Loader.php @@ -79,8 +79,9 @@ class Loader * @throws \Exception * @return \VuFind\RecordDriver\AbstractBase */ - public function load($id, $source = 'VuFind', $tolerateMissing = false) - { + public function load($id, $source = DEFAULT_SEARCH_BACKEND, + $tolerateMissing = false + ) { $results = $this->searchService->retrieve($source, $id)->getRecords(); if (count($results) > 0) { return $results[0]; @@ -106,7 +107,7 @@ class Loader * @throws \Exception * @return array */ - public function loadBatchForSource($ids, $source = 'VuFind') + public function loadBatchForSource($ids, $source = DEFAULT_SEARCH_BACKEND) { return $this->searchService->retrieveBatch($source, $ids)->getRecords(); } diff --git a/module/VuFind/src/VuFind/Record/Router.php b/module/VuFind/src/VuFind/Record/Router.php index 8867121db96..1a382ba66b6 100644 --- a/module/VuFind/src/VuFind/Record/Router.php +++ b/module/VuFind/src/VuFind/Record/Router.php @@ -142,7 +142,7 @@ class Router // Determine route based on naming convention (default VuFind route is // the exception to the rule): - $routeBase = ($source == 'VuFind') + $routeBase = ($source == DEFAULT_SEARCH_BACKEND) ? 'record' : strtolower($source . 'record'); return [ @@ -162,7 +162,7 @@ class Router { $parts = explode('|', $driver, 2); if (count($parts) < 2) { - $source = 'VuFind'; + $source = DEFAULT_SEARCH_BACKEND; $id = $parts[0]; } else { $source = $parts[0]; diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Record.php b/module/VuFind/src/VuFind/View/Helper/Root/Record.php index e8b1ec03b34..e3a7dedb23f 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Record.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Record.php @@ -338,12 +338,12 @@ class Record extends AbstractHelper // Figure out controller using naming convention based on resource // source: $source = $this->driver->getResourceSource(); - if ($source == 'VuFind') { - // "VuFind" is special case -- it refers to Solr, which uses - // the basic record controller. + if ($source == DEFAULT_SEARCH_BACKEND) { + // Default source is special case -- it uses the basic record + // controller. return 'Record'; } - // All non-Solr controllers will correspond with the record source: + // All other controllers will correspond with the record source: return ucwords(strtolower($source)) . 'record'; } diff --git a/module/VuFind/src/VuFind/View/Helper/Root/RecordLink.php b/module/VuFind/src/VuFind/View/Helper/Root/RecordLink.php index 33b387834d2..8e70e9ee58d 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/RecordLink.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/RecordLink.php @@ -148,7 +148,8 @@ class RecordLink extends \Zend\View\Helper\AbstractHelper { if (is_array($url)) { // Assemble URL string from array parts: - $source = isset($url['source']) ? $url['source'] : 'VuFind'; + $source = isset($url['source']) + ? $url['source'] : DEFAULT_SEARCH_BACKEND; $finalUrl = $this->getActionUrl("{$source}|" . $url['record'], $url['action']); if (isset($url['query'])) { diff --git a/public/index.php b/public/index.php index de75a183832..4b204e94c72 100644 --- a/public/index.php +++ b/public/index.php @@ -26,6 +26,9 @@ defined('APPLICATION_ENV') (getenv('VUFIND_ENV') ? getenv('VUFIND_ENV') : 'production') ); +// Define default search backend identifier +defined('DEFAULT_SEARCH_BACKEND') || define('DEFAULT_SEARCH_BACKEND', 'VuFind'); + // Define path to local override directory defined('LOCAL_OVERRIDE_DIR') || define( -- GitLab