The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit 45b013c8 authored by Robert Lange's avatar Robert Lange
Browse files

refs #23119 [finc] make hack for edge case of one record in records controller more specific

* use finc records controller instead of vufind redirect; add check for:
* print: load record and check for missing - otherwise there will be an exception in vufind
* collections: when collections are activated, load record and check for solrdico
parent 3cb8578c
No related merge requests found
......@@ -30,6 +30,7 @@
namespace finc\Controller;
use VuFind\Controller\RecordsController as BaseController;
use VuFind\RecordDriver\AbstractBase;
/**
* Records Controller
......@@ -49,19 +50,41 @@ class RecordsController extends BaseController
*/
protected $suppressJump;
/**
* Driver for each single record
*
* @var array of AbstractBase with key = params and value = driver
*/
protected $driverList;
/**
* Bypass the single record handling of the parent method when printing
* @return bool|mixed|\VuFind\Controller\ViewModel|\Laminas\View\Model\ViewModel
*/
public function homeAction()
{
$this->suppressJump = false;
if ($this->params()->fromQuery('print')) {
$this->suppressJump = true;
return $this->resultsAction();
// If there is only one record, vufind RecordsController redirects
// to record controller - but we (finc) do not want that in some cases
if (count(($params = $this->params()->fromQuery('id', []))) === 1) {
// refs #17990 avoid error for FincMissing after Vufind redirect
if ($this->params()->fromQuery('print')
&& $this->getDriver($params) instanceof \finc\RecordDriver\FincMissing
) {
$this->suppressJump = true;
return $this->resultsAction();
}
// refs #21613 always use collections view if collections are activated (de_15)
$config = $this->serviceLocator->get('VuFind\Config\PluginManager')
->get('config');
if (($config->Collections->collections ?? false)
&& $this->getDriver($params) instanceof \finc\RecordDriver\SolrDico
) {
return $this->resultsAction();
}
}
return $this->resultsAction();
return parent::homeAction();
}
/**
......@@ -109,4 +132,43 @@ class RecordsController extends BaseController
->getTabRouteDetails($recordList[$jumpto - 1]);
return $this->redirect()->toRoute($details['route'], $details['params']);
}
/**
* Get driver for param
*
* @param string $param query id
*
* @return AbstractBase
*/
protected function getDriver($param): AbstractBase
{
$param = is_array($param) ? $param[0] : $param;
if (!isset($this->driverList[$param])) {
[$source, $id] = $this->extractSourceAndId($param);
$this->driverList[$param] = $this->getRecordLoader()
->load($id, $source, true);
}
return $this->driverList[$param];
}
/**
* Get source and id from string
* Copied from \VuFind\Record\Router
*
* @param string $params query id
*
* @return array
*/
protected function extractSourceAndId($params)
{
$parts = explode('|', $params, 2);
if (count($parts) < 2) {
$source = DEFAULT_SEARCH_BACKEND;
$id = $parts[0];
} else {
$source = $parts[0];
$id = $parts[1];
}
return [$source, $id];
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment