From 9f74e99bb316e24ca7aa9c4fbeaac9759e348813 Mon Sep 17 00:00:00 2001 From: Ere Maijala <ere.maijala@helsinki.fi> Date: Tue, 15 Dec 2020 11:37:31 +0200 Subject: [PATCH] Add possibility to reset Demo driver's cache. This can be accomplished by adding clear_demo=1 parameter to any VuFind url that uses the Demo driver. --- module/VuFind/src/VuFind/ILS/Driver/Demo.php | 23 +++++++++++++++---- .../src/VuFind/ILS/Driver/DemoFactory.php | 6 ++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/module/VuFind/src/VuFind/ILS/Driver/Demo.php b/module/VuFind/src/VuFind/ILS/Driver/Demo.php index 432c0c1c48b..6497deb111c 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Demo.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Demo.php @@ -34,6 +34,7 @@ namespace VuFind\ILS\Driver; use ArrayObject; +use Laminas\Http\Request as HttpRequest; use Laminas\Session\Container as SessionContainer; use VuFind\Date\DateException; use VuFind\Exception\ILS as ILSException; @@ -80,6 +81,13 @@ class Demo extends AbstractBase */ protected $sessionFactory; + /** + * HTTP Request object (if available). + * + * @var ?HttpRequest + */ + protected $request; + /** * Should we return bib IDs in MyResearch responses? * @@ -121,11 +129,12 @@ class Demo extends AbstractBase * @param \VuFind\Date\Converter $dateConverter Date converter object * @param SearchService $ss Search service * @param callable $sessionFactory Factory function returning - * SessionContainer object - * fake data to simulate consistency and reduce Solr hits + * SessionContainer object for fake data to simulate consistency and reduce Solr + * hits + * @param HttpRequest $request HTTP request object (optional) */ public function __construct(\VuFind\Date\Converter $dateConverter, - SearchService $ss, $sessionFactory + SearchService $ss, $sessionFactory, HttpRequest $request = null ) { $this->dateConverter = $dateConverter; $this->searchService = $ss; @@ -133,6 +142,7 @@ class Demo extends AbstractBase throw new \Exception('Invalid session factory passed to constructor.'); } $this->sessionFactory = $sessionFactory; + $this->request = $request; } /** @@ -574,7 +584,12 @@ class Demo extends AbstractBase $factory = $this->sessionFactory; $this->session[$selectedPatron] = $factory($selectedPatron); } - return $this->session[$selectedPatron]; + $result = $this->session[$selectedPatron]; + // Special case: check for clear_demo request parameter to reset: + if ($this->request && $this->request->getQuery('clear_demo')) { + $result->exchangeArray([]); + } + return $result; } /** diff --git a/module/VuFind/src/VuFind/ILS/Driver/DemoFactory.php b/module/VuFind/src/VuFind/ILS/Driver/DemoFactory.php index ca5a3c6980d..236d580d8a5 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/DemoFactory.php +++ b/module/VuFind/src/VuFind/ILS/Driver/DemoFactory.php @@ -69,7 +69,11 @@ class DemoFactory extends DriverWithDateConverterFactory }; return parent::__invoke( $container, $requestedName, - [$container->get(\VuFindSearch\Service::class), $sessionFactory] + [ + $container->get(\VuFindSearch\Service::class), + $sessionFactory, + $container->get('Request') + ] ); } } -- GitLab