diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index fc1b96b0a6699ca83c38792ae149e8d5d9a17416..daa5a60d2a91f1a7d9c714c1d859bd03b445476f 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -63,6 +63,7 @@ $config = [ 'controllers' => [ 'factories' => [ 'browse' => 'VuFind\Controller\Factory::getBrowseController', + 'cart' => 'VuFind\Controller\Factory::getCartController', 'collection' => 'VuFind\Controller\Factory::getCollectionController', 'collections' => 'VuFind\Controller\Factory::getCollectionsController', 'record' => 'VuFind\Controller\Factory::getRecordController', @@ -73,7 +74,6 @@ $config = [ 'alphabrowse' => 'VuFind\Controller\AlphabrowseController', 'author' => 'VuFind\Controller\AuthorController', 'authority' => 'VuFind\Controller\AuthorityController', - 'cart' => 'VuFind\Controller\CartController', 'combined' => 'VuFind\Controller\CombinedController', 'confirm' => 'VuFind\Controller\ConfirmController', 'cover' => 'VuFind\Controller\CoverController', @@ -105,25 +105,23 @@ $config = [ 'worldcat' => 'VuFind\Controller\WorldcatController', 'worldcatrecord' => 'VuFind\Controller\WorldcatrecordController', ], - 'initializers' => [ - 'ZfcRbac\Initializer\AuthorizationServiceInitializer' - ], ], 'controller_plugins' => [ 'factories' => [ + 'flashmessenger' => 'VuFind\Controller\Plugin\Factory::getFlashMessenger', + 'followup' => 'VuFind\Controller\Plugin\Factory::getFollowup', 'holds' => 'VuFind\Controller\Plugin\Factory::getHolds', 'newitems' => 'VuFind\Controller\Plugin\Factory::getNewItems', 'ILLRequests' => 'VuFind\Controller\Plugin\Factory::getILLRequests', 'recaptcha' => 'VuFind\Controller\Plugin\Factory::getRecaptcha', 'reserves' => 'VuFind\Controller\Plugin\Factory::getReserves', + 'result-scroller' => 'VuFind\Controller\Plugin\Factory::getResultScroller', 'storageRetrievalRequests' => 'VuFind\Controller\Plugin\Factory::getStorageRetrievalRequests', ], 'invokables' => [ 'db-upgrade' => 'VuFind\Controller\Plugin\DbUpgrade', 'favorites' => 'VuFind\Controller\Plugin\Favorites', - 'followup' => 'VuFind\Controller\Plugin\Followup', 'renewals' => 'VuFind\Controller\Plugin\Renewals', - 'result-scroller' => 'VuFind\Controller\Plugin\ResultScroller', ] ], 'service_manager' => [ @@ -173,6 +171,7 @@ $config = [ 'VuFind\RelatedPluginManager' => 'VuFind\Service\Factory::getRelatedPluginManager', 'VuFind\ResolverDriverPluginManager' => 'VuFind\Service\Factory::getResolverDriverPluginManager', 'VuFind\Search\BackendManager' => 'VuFind\Service\Factory::getSearchBackendManager', + 'VuFind\Search\Memory' => 'VuFind\Service\Factory::getSearchMemory', 'VuFind\SearchOptionsPluginManager' => 'VuFind\Service\Factory::getSearchOptionsPluginManager', 'VuFind\SearchParamsPluginManager' => 'VuFind\Service\Factory::getSearchParamsPluginManager', 'VuFind\SearchResultsPluginManager' => 'VuFind\Service\Factory::getSearchResultsPluginManager', @@ -180,7 +179,8 @@ $config = [ 'VuFind\SearchSpecsReader' => 'VuFind\Service\Factory::getSearchSpecsReader', 'VuFind\SearchStats' => 'VuFind\Service\Factory::getSearchStats', 'VuFind\SearchTabsHelper' => 'VuFind\Service\Factory::getSearchTabsHelper', - 'VuFind\SessionManager' => 'VuFind\Service\Factory::getSessionManager', + 'VuFind\SessionManager' => 'VuFind\Session\ManagerFactory', + 'VuFind\Session\OnDemandContainerFactory' => 'VuFind\Service\Factory::getOnDemandContainerFactory', 'VuFind\SessionPluginManager' => 'VuFind\Service\Factory::getSessionPluginManager', 'VuFind\SMS' => 'VuFind\SMS\Factory', 'VuFind\Solr\Writer' => 'VuFind\Service\Factory::getSolrWriter', @@ -192,8 +192,8 @@ $config = [ 'invokables' => [ 'VuFind\HierarchicalFacetHelper' => 'VuFind\Search\Solr\HierarchicalFacetHelper', 'VuFind\IpAddressUtils' => 'VuFind\Net\IpAddressUtils', - 'VuFind\Search' => 'VuFindSearch\Service', - 'VuFind\Search\Memory' => 'VuFind\Search\Memory', + 'VuFind\Search' => 'VuFindSearch\Service', + 'VuFind\Session\Settings' => 'VuFind\Session\Settings', ], 'initializers' => [ 'VuFind\ServiceManager\Initializer::initInstance', @@ -243,14 +243,14 @@ $config = [ 'auth' => [ 'abstract_factories' => ['VuFind\Auth\PluginFactory'], 'factories' => [ + 'choiceauth' => 'VuFind\Auth\Factory::getChoiceAuth', + 'facebook' => 'VuFind\Auth\Factory::getFacebook', 'ils' => 'VuFind\Auth\Factory::getILS', 'multiils' => 'VuFind\Auth\Factory::getMultiILS', ], 'invokables' => [ 'cas' => 'VuFind\Auth\CAS', - 'choiceauth' => 'VuFind\Auth\ChoiceAuth', 'database' => 'VuFind\Auth\Database', - 'facebook' => 'VuFind\Auth\Facebook', 'ldap' => 'VuFind\Auth\LDAP', 'multiauth' => 'VuFind\Auth\MultiAuth', 'shibboleth' => 'VuFind\Auth\Shibboleth', @@ -337,6 +337,7 @@ $config = [ 'factories' => [ 'resource' => 'VuFind\Db\Table\Factory::getResource', 'user' => 'VuFind\Db\Table\Factory::getUser', + 'userlist' => 'VuFind\Db\Table\Factory::getUserList', ], 'invokables' => [ 'changetracker' => 'VuFind\Db\Table\ChangeTracker', @@ -347,7 +348,6 @@ $config = [ 'search' => 'VuFind\Db\Table\Search', 'session' => 'VuFind\Db\Table\Session', 'tags' => 'VuFind\Db\Table\Tags', - 'userlist' => 'VuFind\Db\Table\UserList', 'userresource' => 'VuFind\Db\Table\UserResource', 'userstats' => 'VuFind\Db\Table\UserStats', 'userstatsfields' => 'VuFind\Db\Table\UserStatsFields', diff --git a/module/VuFind/src/VuFind/Auth/ChoiceAuth.php b/module/VuFind/src/VuFind/Auth/ChoiceAuth.php index 8df21c11a16aa06cf0ed60df60f839824aacedca..c141aa3cc9ba90147303d13cb9267c175f4c1214 100644 --- a/module/VuFind/src/VuFind/Auth/ChoiceAuth.php +++ b/module/VuFind/src/VuFind/Auth/ChoiceAuth.php @@ -75,11 +75,14 @@ class ChoiceAuth extends AbstractBase /** * Constructor + * + * @param \Zend\Session\Container $container Session container for retaining + * user choices. */ - public function __construct() + public function __construct(\Zend\Session\Container $container) { // Set up session container and load cached strategy (if found): - $this->session = new \Zend\Session\Container('ChoiceAuth'); + $this->session = $container; $this->strategy = isset($this->session->auth_method) ? $this->session->auth_method : false; } diff --git a/module/VuFind/src/VuFind/Auth/Facebook.php b/module/VuFind/src/VuFind/Auth/Facebook.php index 1bfd40cba15bb6958a634b24c08d83fe6d34e4c3..3bd2e4598c1af95bf176ac3dec2208885823e9c8 100644 --- a/module/VuFind/src/VuFind/Auth/Facebook.php +++ b/module/VuFind/src/VuFind/Auth/Facebook.php @@ -53,10 +53,13 @@ class Facebook extends AbstractBase implements /** * Constructor + * + * @param \Zend\Session\Container $container Session container for persisting + * state information. */ - public function __construct() + public function __construct(\Zend\Session\Container $container) { - $this->session = new \Zend\Session\Container('Facebook'); + $this->session = $container; } /** diff --git a/module/VuFind/src/VuFind/Auth/Factory.php b/module/VuFind/src/VuFind/Auth/Factory.php index 4c9409558533aaa0bc176a3eb8b56f5bb949405d..6b63bd98d7df86555639c9962f4555d7cf35bd6a 100644 --- a/module/VuFind/src/VuFind/Auth/Factory.php +++ b/module/VuFind/src/VuFind/Auth/Factory.php @@ -41,6 +41,36 @@ use Zend\ServiceManager\ServiceManager; */ class Factory { + /** + * Construct the ChoiceAuth plugin. + * + * @param ServiceManager $sm Service manager. + * + * @return ChoiceAuth + */ + public static function getChoiceAuth(ServiceManager $sm) + { + $container = new \Zend\Session\Container( + 'ChoiceAuth', $sm->getServiceLocator()->get('VuFind\SessionManager') + ); + return new ChoiceAuth($container); + } + + /** + * Construct the Facebook plugin. + * + * @param ServiceManager $sm Service manager. + * + * @return Facebook + */ + public static function getFacebook(ServiceManager $sm) + { + $container = new \Zend\Session\Container( + 'Facebook', $sm->getServiceLocator()->get('VuFind\SessionManager') + ); + return new Facebook($container); + } + /** * Construct the ILS plugin. * @@ -117,8 +147,10 @@ class Factory $pm = $sm->get('VuFind\AuthPluginManager'); $cookies = $sm->get('VuFind\CookieManager'); - // Build the object: - return new Manager($config, $userTable, $sessionManager, $pm, $cookies); + // Build the object and make sure account credentials haven't expired: + $manager = new Manager($config, $userTable, $sessionManager, $pm, $cookies); + $manager->checkForExpiredCredentials(); + return $manager; } /** diff --git a/module/VuFind/src/VuFind/Auth/Manager.php b/module/VuFind/src/VuFind/Auth/Manager.php index c81c089f0487d68c09bef91c76b8e778210d846b..dfa1b4404f11be0231e51e18067a94189551ee1d 100644 --- a/module/VuFind/src/VuFind/Auth/Manager.php +++ b/module/VuFind/src/VuFind/Auth/Manager.php @@ -133,7 +133,7 @@ class Manager implements \ZfcRbac\Identity\IdentityProviderInterface $this->cookieManager = $cookieManager; // Set up session: - $this->session = new \Zend\Session\Container('Account'); + $this->session = new \Zend\Session\Container('Account', $sessionManager); // Set up CSRF: $this->csrf = new Csrf( diff --git a/module/VuFind/src/VuFind/Bootstrapper.php b/module/VuFind/src/VuFind/Bootstrapper.php index d7c61c21612752d628f66932ee56074de0fe7225..1d139917e6930cab24f6687206179640e47d43c5 100644 --- a/module/VuFind/src/VuFind/Bootstrapper.php +++ b/module/VuFind/src/VuFind/Bootstrapper.php @@ -100,52 +100,6 @@ class Bootstrapper $this->config = $serviceManager->get('VuFind\Config')->get('config'); } - /** - * Set up the session. This should be done early since other startup routines - * may rely on session access. - * - * @return void - */ - protected function initSession() - { - // Don't bother with session in CLI mode (it just causes error messages): - if (Console::isConsole()) { - return; - } - - // Get session configuration: - if (!isset($this->config->Session->type)) { - throw new \Exception('Cannot initialize session; configuration missing'); - } - - // Set up the session handler by retrieving all the pieces from the service - // manager and injecting appropriate dependencies: - $serviceManager = $this->event->getApplication()->getServiceManager(); - $sessionManager = $serviceManager->get('VuFind\SessionManager'); - $sessionPluginManager = $serviceManager->get('VuFind\SessionPluginManager'); - $sessionHandler = $sessionPluginManager->get($this->config->Session->type); - $sessionHandler->setConfig($this->config->Session); - $sessionManager->setSaveHandler($sessionHandler); - - // Start up the session: - $sessionManager->start(); - - // According to the PHP manual, session_write_close should always be - // registered as a shutdown function when using an object as a session - // handler: http://us.php.net/manual/en/function.session-set-save-handler.php - register_shutdown_function( - function () use ($sessionManager) { - // If storage is immutable, the session is already closed: - if (!$sessionManager->getStorage()->isImmutable()) { - $sessionManager->writeClose(); - } - } - ); - - // Make sure account credentials haven't expired: - $serviceManager->get('VuFind\AuthManager')->checkForExpiredCredentials(); - } - /** * Initialize dynamic debug mode (debug initiated by a ?debug=true parameter). * diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php index 1bae4f1ac2a2a10f272547f9999e2af30df21496..c5cd324b21604c58a0d45732bd60d2a6c98b0d9b 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractBase.php +++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php @@ -48,10 +48,7 @@ use VuFind\Exception\Forbidden as ForbiddenException, * @SuppressWarnings(PHPMD.NumberOfChildren) */ class AbstractBase extends AbstractActionController - implements AuthorizationServiceAwareInterface { - use AuthorizationServiceAwareTrait; - /** * Permission that must be granted to access this module (false for no * restriction) @@ -200,6 +197,19 @@ class AbstractBase extends AbstractActionController return $this->getServiceLocator()->get('VuFind\AuthManager'); } + /** + * Get the authorization service (note that we're doing this on-demand + * rather than through injection with the AuthorizationServiceAwareInterface + * to minimize expensive initialization when authorization is not needed. + * + * @return \ZfcRbac\Service\AuthorizationService + */ + protected function getAuthorizationService() + { + return $this->getServiceLocator() + ->get('ZfcRbac\Service\AuthorizationService'); + } + /** * Get the ILS authenticator. * @@ -605,16 +615,16 @@ class AbstractBase extends AbstractActionController } /** - * Write the session -- this is designed to be called prior to time-consuming - * AJAX operations. This should help reduce the odds of a timing-related bug + * Prevent session writes -- this is designed to be called prior to time- + * consuming AJAX operations to help reduce the odds of a timing-related bug * that causes the wrong version of session data to be written to disk (see * VUFIND-716 for more details). * * @return void */ - protected function writeSession() + protected function disableSessionWrites() { - $this->getServiceLocator()->get('VuFind\SessionManager')->writeClose(); + $this->getServiceLocator()->get('VuFind\Session\Settings')->disableWrite(); } /** diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index ef63b9b9c13e4ade9f72c3f4d65eb1146188c854..128297f3921c22fb2f38640c35fe7b67a7be025b 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -106,7 +106,7 @@ class AjaxController extends AbstractBase */ public function recommendAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug // Process recommendations -- for now, we assume Solr-based search objects, // since deferred recommendations work best for modules that don't care about // the details of the search objects anyway: @@ -187,7 +187,7 @@ class AjaxController extends AbstractBase */ protected function getItemStatusesAjax() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $catalog = $this->getILS(); $ids = $this->params()->fromPost('id', $this->params()->fromQuery('id')); $results = $catalog->getStatuses($ids); @@ -513,7 +513,7 @@ class AjaxController extends AbstractBase */ protected function getSaveStatusesAjax() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug // check if user is logged in $user = $this->getUser(); if (!$user) { @@ -758,7 +758,7 @@ class AjaxController extends AbstractBase */ protected function getMapDataAjax($fields = ['long_lat']) { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $results = $this->getResultsManager()->get('Solr'); $params = $results->getParams(); $params->initFromRequest($this->getRequest()->getQuery()); @@ -793,7 +793,7 @@ class AjaxController extends AbstractBase */ public function resultgooglemapinfoAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug // Set layout to render the page inside a lightbox: $this->layout()->setTemplate('layout/lightbox'); @@ -823,7 +823,7 @@ class AjaxController extends AbstractBase */ protected function getVisDataAjax($fields = ['publishDate']) { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $results = $this->getResultsManager()->get('Solr'); $params = $results->getParams(); $params->initFromRequest($this->getRequest()->getQuery()); @@ -916,7 +916,7 @@ class AjaxController extends AbstractBase */ protected function getACSuggestionsAjax() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $query = $this->getRequest()->getQuery(); $autocompleteManager = $this->getServiceLocator() ->get('VuFind\AutocompletePluginManager'); @@ -932,7 +932,7 @@ class AjaxController extends AbstractBase */ protected function checkRequestIsValidAjax() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $id = $this->params()->fromQuery('id'); $data = $this->params()->fromQuery('data'); $requestType = $this->params()->fromQuery('requestType'); @@ -1113,7 +1113,7 @@ class AjaxController extends AbstractBase */ protected function getResolverLinksAjax() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $openUrl = $this->params()->fromQuery('openurl', ''); $searchClassId = $this->params()->fromQuery('searchClassId', ''); @@ -1199,7 +1199,7 @@ class AjaxController extends AbstractBase */ protected function getLibraryPickupLocationsAjax() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $id = $this->params()->fromQuery('id'); $pickupLib = $this->params()->fromQuery('pickupLib'); if (empty($id) || empty($pickupLib)) { @@ -1251,7 +1251,7 @@ class AjaxController extends AbstractBase */ protected function getRequestGroupPickupLocationsAjax() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $id = $this->params()->fromQuery('id'); $requestGroupId = $this->params()->fromQuery('requestGroupId'); if (empty($id) || empty($requestGroupId)) { @@ -1314,7 +1314,7 @@ class AjaxController extends AbstractBase */ protected function getFacetDataAjax() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $facet = $this->params()->fromQuery('facetName'); $sort = $this->params()->fromQuery('facetSort'); diff --git a/module/VuFind/src/VuFind/Controller/CartController.php b/module/VuFind/src/VuFind/Controller/CartController.php index 2ef4a3c73fef2358eff4f414517352c5a087c3cd..0f613f7b9c66617605ff8c9e2976d44148adbf04 100644 --- a/module/VuFind/src/VuFind/Controller/CartController.php +++ b/module/VuFind/src/VuFind/Controller/CartController.php @@ -26,8 +26,7 @@ * @link https://vufind.org Main Site */ namespace VuFind\Controller; -use VuFind\Exception\Mail as MailException, - Zend\Session\Container as SessionContainer; +use VuFind\Exception\Mail as MailException; /** * Book Bag / Bulk Action Controller @@ -43,17 +42,19 @@ class CartController extends AbstractBase /** * Session container * - * @var SessionContainer + * @var \Zend\Session\Container */ protected $session; /** * Constructor + * + * @param \Zend\Session\Container $container Session container */ - public function __construct() + public function __construct(\Zend\Session\Container $container) { parent::__construct(); - $this->session = new SessionContainer('cart_followup'); + $this->session = $container; } /** diff --git a/module/VuFind/src/VuFind/Controller/CombinedController.php b/module/VuFind/src/VuFind/Controller/CombinedController.php index 350df2e29140a4d682b38b1dc4c3c872da98306f..281449c730833cdec4c64288ece3e6eea117880a 100644 --- a/module/VuFind/src/VuFind/Controller/CombinedController.php +++ b/module/VuFind/src/VuFind/Controller/CombinedController.php @@ -64,7 +64,7 @@ class CombinedController extends AbstractSearch */ public function resultAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug // Turn off search memory -- not relevant in this context: $this->getSearchMemory()->disable(); diff --git a/module/VuFind/src/VuFind/Controller/CoverController.php b/module/VuFind/src/VuFind/Controller/CoverController.php index 8ce95cd90487494b7aebb5cbbea203afd601162b..310980d4ffa2a22322e5d1f5d4a827dab48cf4e2 100644 --- a/module/VuFind/src/VuFind/Controller/CoverController.php +++ b/module/VuFind/src/VuFind/Controller/CoverController.php @@ -135,7 +135,7 @@ class CoverController extends AbstractBase */ public function showAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug // Special case: proxy a full URL: $proxy = $this->params()->fromQuery('proxy'); @@ -164,7 +164,7 @@ class CoverController extends AbstractBase */ public function unavailableAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $this->getLoader()->loadUnavailable(); return $this->displayImage(); } diff --git a/module/VuFind/src/VuFind/Controller/Factory.php b/module/VuFind/src/VuFind/Controller/Factory.php index ade1d001c0b25b71f4872d10c99405e7c352b6c9..7453f8dd931b029239441a61a470d49cf931ceab 100644 --- a/module/VuFind/src/VuFind/Controller/Factory.php +++ b/module/VuFind/src/VuFind/Controller/Factory.php @@ -55,6 +55,23 @@ class Factory ); } + /** + * Construct the CartController. + * + * @param ServiceManager $sm Service manager. + * + * @return BrowseController + */ + public static function getCartController(ServiceManager $sm) + { + return new CartController( + new \Zend\Session\Container( + 'cart_followup', + $sm->getServiceLocator()->get('VuFind\SessionManager') + ) + ); + } + /** * Construct the CollectionController. * @@ -107,7 +124,10 @@ class Factory public static function getUpgradeController(ServiceManager $sm) { return new UpgradeController( - $sm->getServiceLocator()->get('VuFind\CookieManager') + $sm->getServiceLocator()->get('VuFind\CookieManager'), + new \Zend\Session\Container( + 'upgrade', $sm->getServiceLocator()->get('VuFind\SessionManager') + ) ); } } diff --git a/module/VuFind/src/VuFind/Controller/HierarchyController.php b/module/VuFind/src/VuFind/Controller/HierarchyController.php index fe798b928262e9687e69417af6f619b48c0e8864..3794aa6e2f84604fc203b4cb2aaf4adf8dc2a0fc 100644 --- a/module/VuFind/src/VuFind/Controller/HierarchyController.php +++ b/module/VuFind/src/VuFind/Controller/HierarchyController.php @@ -80,7 +80,7 @@ class HierarchyController extends AbstractBase */ public function searchtreeAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $config = $this->getConfig(); $limit = isset($config->Hierarchy->treeSearchLimit) ? $config->Hierarchy->treeSearchLimit : -1; @@ -117,7 +117,7 @@ class HierarchyController extends AbstractBase */ public function gettreeAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug // Retrieve the record from the index $id = $this->params()->fromQuery('id'); $loader = $this->getServiceLocator()->get('VuFind\RecordLoader'); @@ -150,7 +150,7 @@ class HierarchyController extends AbstractBase */ public function gettreejsonAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug // Retrieve the record from the index $id = $this->params()->fromQuery('id'); $loader = $this->getServiceLocator()->get('VuFind\RecordLoader'); diff --git a/module/VuFind/src/VuFind/Controller/Plugin/AbstractRequestBase.php b/module/VuFind/src/VuFind/Controller/Plugin/AbstractRequestBase.php index 441caaea6d10a7f33d1dd47b3f1f05ce9c241f1f..a7c67fab69002761cceae32b9272c9aabeb2e9a2 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/AbstractRequestBase.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/AbstractRequestBase.php @@ -26,8 +26,9 @@ * @link https://vufind.org Main Page */ namespace VuFind\Controller\Plugin; -use VuFind\ILS\Connection; -use Zend\Mvc\Controller\Plugin\AbstractPlugin, Zend\Session\Container; +use VuFind\Crypt\HMAC, VuFind\ILS\Connection; +use Zend\Mvc\Controller\Plugin\AbstractPlugin, Zend\Session\Container, + Zend\Session\SessionManager; /** * Zend action helper base class to perform request-related actions @@ -47,21 +48,30 @@ abstract class AbstractRequestBase extends AbstractPlugin */ protected $session; + /** + * Session manager + * + * @var SessionManager + */ + protected $sessionManager; + /** * HMAC generator * - * @var \VuFind\Crypt\HMAC + * @var HMAC */ protected $hmac; /** * Constructor * - * @param \VuFind\Crypt\HMAC $hmac HMAC generator + * @param HMAC $hmac HMAC generator + * @param SessionManager $sessionManager Session manager */ - public function __construct(\VuFind\Crypt\HMAC $hmac) + public function __construct(HMAC $hmac, SessionManager $sessionManager) { $this->hmac = $hmac; + $this->sessionManager = $sessionManager; } /** @@ -73,7 +83,9 @@ abstract class AbstractRequestBase extends AbstractPlugin protected function getSession() { if (!isset($this->session)) { - $this->session = new Container(get_class($this) . '_Helper'); + $this->session = new Container( + get_class($this) . '_Helper', $this->sessionManager + ); } return $this->session; } diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Factory.php b/module/VuFind/src/VuFind/Controller/Plugin/Factory.php index ee75413bb1d3d6f376fc9d6221cc6228e8266f89..15b2c3c4413bfa804be580f2aa24c95019489286 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/Factory.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/Factory.php @@ -41,6 +41,37 @@ use Zend\ServiceManager\ServiceManager; */ class Factory { + /** + * Construct the FlashMessenger plugin. + * + * @param ServiceManager $sm Service manager. + * + * @return \Zend\Mvc\Controller\Plugin\FlashMessenger + */ + public static function getFlashMessenger(ServiceManager $sm) + { + $plugin = new \Zend\Mvc\Controller\Plugin\FlashMessenger(); + $sessionManager = $sm->getServiceLocator()->get('VuFind\SessionManager'); + $plugin->setSessionManager($sessionManager); + return $plugin; + } + + /** + * Construct the Followup plugin. + * + * @param ServiceManager $sm Service manager. + * + * @return Followup + */ + public static function getFollowup(ServiceManager $sm) + { + return new Followup( + new \Zend\Session\Container( + 'Followup', $sm->getServiceLocator()->get('VuFind\SessionManager') + ) + ); + } + /** * Construct the Holds plugin. * @@ -50,7 +81,10 @@ class Factory */ public static function getHolds(ServiceManager $sm) { - return new Holds($sm->getServiceLocator()->get('VuFind\HMAC')); + return new Holds( + $sm->getServiceLocator()->get('VuFind\HMAC'), + $sm->getServiceLocator()->get('VuFind\SessionManager') + ); } /** @@ -78,7 +112,8 @@ class Factory public static function getILLRequests(ServiceManager $sm) { return new ILLRequests( - $sm->getServiceLocator()->get('VuFind\HMAC') + $sm->getServiceLocator()->get('VuFind\HMAC'), + $sm->getServiceLocator()->get('VuFind\SessionManager') ); } @@ -113,6 +148,23 @@ class Factory return new Reserves($useIndex); } + /** + * Construct the ResultScroller plugin. + * + * @param ServiceManager $sm Service manager. + * + * @return ResultScroller + */ + public static function getResultScroller(ServiceManager $sm) + { + return new ResultScroller( + new \Zend\Session\Container( + 'ResultScroller', + $sm->getServiceLocator()->get('VuFind\SessionManager') + ) + ); + } + /** * Construct the StorageRetrievalRequests plugin. * @@ -123,7 +175,8 @@ class Factory public static function getStorageRetrievalRequests(ServiceManager $sm) { return new StorageRetrievalRequests( - $sm->getServiceLocator()->get('VuFind\HMAC') + $sm->getServiceLocator()->get('VuFind\HMAC'), + $sm->getServiceLocator()->get('VuFind\SessionManager') ); } } diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Followup.php b/module/VuFind/src/VuFind/Controller/Plugin/Followup.php index 6f35c634fbd3f52a3f631a7c845fb9a9f1280a69..bc9a0d7505c3d1ac79fd2be9d033f8aa82d08e93 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/Followup.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/Followup.php @@ -49,10 +49,12 @@ class Followup extends AbstractPlugin /** * Constructor + * + * @param Container $session Session container */ - public function __construct() + public function __construct(Container $session) { - $this->session = new Container('Followup'); + $this->session = $session; } /** diff --git a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php index 875b7b159a533179a14ce58c47a1008b5fa6b076..fde08a082a25c3b513be7c2218e30627c200ea80 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php @@ -57,14 +57,15 @@ class ResultScroller extends AbstractPlugin /** * Constructor. Create a new search result scroller. * - * @param bool $enabled Is the scroller enabled? + * @param SessionContainer $session Session container + * @param bool $enabled Is the scroller enabled? */ - public function __construct($enabled = true) + public function __construct(SessionContainer $session, $enabled = true) { $this->enabled = $enabled; // Set up session namespace for the class. - $this->data = new SessionContainer('ResultScroller'); + $this->data = $session; } /** diff --git a/module/VuFind/src/VuFind/Controller/QRCodeController.php b/module/VuFind/src/VuFind/Controller/QRCodeController.php index 35f88de22eb94d67e9ec6eb6673d729e82cd73b1..7f2b3dd27eca13d05c82edfc6a6b39e4fb260235 100644 --- a/module/VuFind/src/VuFind/Controller/QRCodeController.php +++ b/module/VuFind/src/VuFind/Controller/QRCodeController.php @@ -75,7 +75,7 @@ class QRCodeController extends AbstractBase */ public function showAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $this->getLoader()->loadQRCode( $this->params()->fromQuery('text'), @@ -95,7 +95,7 @@ class QRCodeController extends AbstractBase */ public function unavailableAction() { - $this->writeSession(); // avoid session write timing bug + $this->disableSessionWrites(); // avoid session write timing bug $this->getLoader()->loadUnavailable(); return $this->displayQRCode(); } diff --git a/module/VuFind/src/VuFind/Controller/UpgradeController.php b/module/VuFind/src/VuFind/Controller/UpgradeController.php index c7b8f1700d3a6ba907e7358053bbeac75ed9329c..1899ebdadcd80c63da49de93733dff16b4888d51 100644 --- a/module/VuFind/src/VuFind/Controller/UpgradeController.php +++ b/module/VuFind/src/VuFind/Controller/UpgradeController.php @@ -29,8 +29,7 @@ namespace VuFind\Controller; use ArrayObject, VuFind\Config\Locator as ConfigLocator, VuFind\Cookie\Container as CookieContainer, VuFind\Exception\RecordMissing as RecordMissingException, - Zend\Mvc\MvcEvent, - Zend\Session\Container as SessionContainer; + Zend\Mvc\MvcEvent; /** * Class controls VuFind upgrading. @@ -53,7 +52,7 @@ class UpgradeController extends AbstractBase /** * Session container * - * @var SessionContainer + * @var \Zend\Session\Container */ protected $session; @@ -67,10 +66,12 @@ class UpgradeController extends AbstractBase /** * Constructor * - * @param \VuFind\Cookie\CookieManager $cookieManager Cookie manager + * @param \VuFind\Cookie\CookieManager $cookieManager Cookie manager + * @param \Zend\Session\Container $sessionContainer Session container */ - public function __construct(\VuFind\Cookie\CookieManager $cookieManager) - { + public function __construct(\VuFind\Cookie\CookieManager $cookieManager, + \Zend\Session\Container $sessionContainer + ) { // We want to use cookies for tracking the state of the upgrade, since the // session is unreliable -- if the user upgrades a configuration that uses // a different session handler than the default one, we'll lose track of our @@ -81,7 +82,7 @@ class UpgradeController extends AbstractBase // safely use the session for storing some values. We'll use this for the // temporary storage of root database credentials, since it is unwise to // send such sensitive values around as cookies! - $this->session = new SessionContainer('upgrade'); + $this->session = $sessionContainer; // We should also use the session for storing warnings once we know it will // be stable; this will prevent the cookies from getting too big. diff --git a/module/VuFind/src/VuFind/Db/Row/PrivateUser.php b/module/VuFind/src/VuFind/Db/Row/PrivateUser.php index f0fe765ddaf59dea5a587dc78377ca7addf8b324..40034e3d9f9a08a32b3550cf3eee6c9b0b9f7c3a 100644 --- a/module/VuFind/src/VuFind/Db/Row/PrivateUser.php +++ b/module/VuFind/src/VuFind/Db/Row/PrivateUser.php @@ -38,6 +38,13 @@ namespace VuFind\Db\Row; */ class PrivateUser extends User { + /** + * Session container for account information. + * + * @var \Zend\Session\Container + */ + protected $session = null; + /** * __get * @@ -70,8 +77,22 @@ class PrivateUser extends User { $this->initialize(); $this->id = -1; // fake ID - $session = new \Zend\Session\Container('Account'); - $session->userDetails = $this->toArray(); + if (null === $this->session) { + throw new \Exception('Expected session container missing.'); + } + $this->session->userDetails = $this->toArray(); return 1; } + + /** + * Set session container + * + * @param \Zend\Session\Container $session Session container + * + * @return void + */ + public function setSession(\Zend\Session\Container $session) + { + $this->session = $session; + } } diff --git a/module/VuFind/src/VuFind/Db/Row/UserList.php b/module/VuFind/src/VuFind/Db/Row/UserList.php index 736c7c72fbc8fd9abda484b495c772870794fb5c..c25aeaed17762dbb91d5ff89c64ee7fd422a05d2 100644 --- a/module/VuFind/src/VuFind/Db/Row/UserList.php +++ b/module/VuFind/src/VuFind/Db/Row/UserList.php @@ -27,8 +27,7 @@ */ namespace VuFind\Db\Row; use VuFind\Exception\ListPermission as ListPermissionException, - VuFind\Exception\MissingField as MissingFieldException, - Zend\Session\Container as SessionContainer; + VuFind\Exception\MissingField as MissingFieldException; /** * Row Definition for user_list @@ -43,6 +42,13 @@ class UserList extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterf { use \VuFind\Db\Table\DbTableAwareTrait; + /** + * Session container for last list information. + * + * @var \Zend\Session\Container + */ + protected $session = null; + /** * Constructor * @@ -131,26 +137,28 @@ class UserList extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterf } /** - * Remember that this list was used so that it can become the default in - * dialog boxes. + * Set session container + * + * @param \Zend\Session\Container $session Session container * * @return void */ - public function rememberLastUsed() + public function setSession(\Zend\Session\Container $session) { - $session = new SessionContainer('List'); - $session->lastUsed = $this->id; + $this->session = $session; } /** - * Retrieve the ID of the last list that was accessed, if any. + * Remember that this list was used so that it can become the default in + * dialog boxes. * - * @return mixed User_list ID (if set) or null (if not available). + * @return void */ - public static function getLastUsed() + public function rememberLastUsed() { - $session = new SessionContainer('List'); - return isset($session->lastUsed) ? $session->lastUsed : null; + if (null !== $this->session) { + $this->session->lastUsed = $this->id; + } } /** diff --git a/module/VuFind/src/VuFind/Db/Table/Factory.php b/module/VuFind/src/VuFind/Db/Table/Factory.php index 4b5b8c1d2237d9bf8baaa07339e3887b824c36bd..0369a3c7d2375b9fc95613b239b9404048af165c 100644 --- a/module/VuFind/src/VuFind/Db/Table/Factory.php +++ b/module/VuFind/src/VuFind/Db/Table/Factory.php @@ -62,8 +62,30 @@ class Factory */ public static function getUser(ServiceManager $sm) { - return new User( - $sm->getServiceLocator()->get('VuFind\Config')->get('config') - ); + $config = $sm->getServiceLocator()->get('VuFind\Config')->get('config'); + // Use a special row class when we're in privacy mode: + $privacy = isset($config->Authentication->privacy) + && $config->Authentication->privacy; + $rowClass = 'VuFind\Db\Row\\' . ($privacy ? 'PrivateUser' : 'User'); + $session = null; + if ($privacy) { + $sessionManager = $sm->getServiceLocator()->get('VuFind\SessionManager'); + $session = new \Zend\Session\Container('Account', $sessionManager); + } + return new User($config, $rowClass, $session); + } + + /** + * Construct the UserList table. + * + * @param ServiceManager $sm Service manager. + * + * @return UserList + */ + public static function getUserList(ServiceManager $sm) + { + $sessionManager = $sm->getServiceLocator()->get('VuFind\SessionManager'); + $session = new \Zend\Session\Container('List', $sessionManager); + return new UserList($session); } } diff --git a/module/VuFind/src/VuFind/Db/Table/User.php b/module/VuFind/src/VuFind/Db/Table/User.php index 40688a586b30b1d2c854803dd4b9a0d94791ed67..158475e98c3b1628ca4390080bc9c5f4ce110ed6 100644 --- a/module/VuFind/src/VuFind/Db/Table/User.php +++ b/module/VuFind/src/VuFind/Db/Table/User.php @@ -26,6 +26,7 @@ * @link https://vufind.org Main Site */ namespace VuFind\Db\Table; +use Zend\Config\Config, Zend\Session\Container; /** * Table Definition for user @@ -41,23 +42,31 @@ class User extends Gateway /** * VuFind configuration * - * @var \Zend\Config\Config + * @var Config */ protected $config; + /** + * Session container + * + * @var Container + */ + protected $session; + /** * Constructor * - * @param \Zend\Config\Config $config VuFind configuration + * @param Config $config VuFind configuration + * @param string $rowClass Name of class for representing rows + * @param Container $session Session container to inject into rows (optional; + * used for privacy mode) */ - public function __construct(\Zend\Config\Config $config) - { - // Use a special row class when we're in privacy mode: - $privacy = isset($config->Authentication->privacy) - && $config->Authentication->privacy; - $rowClass = 'VuFind\Db\Row\\' . ($privacy ? 'PrivateUser' : 'User'); + public function __construct(Config $config, $rowClass = 'VuFind\Db\Row\User', + Container $session = null + ) { parent::__construct('user', $rowClass); $this->config = $config; + $this->session = $session; } /** @@ -128,6 +137,9 @@ class User extends Gateway { $prototype = parent::initializeRowPrototype(); $prototype->setConfig($this->config); + if (null !== $this->session && is_callable([$prototype, 'setSession'])) { + $prototype->setSession($this->session); + } return $prototype; } diff --git a/module/VuFind/src/VuFind/Db/Table/UserList.php b/module/VuFind/src/VuFind/Db/Table/UserList.php index 8267238efe54b4fe2366e5dfa6686ecc8bcc20b2..2fd8cd44f4c497e4192873a651434bc4dae6e13f 100644 --- a/module/VuFind/src/VuFind/Db/Table/UserList.php +++ b/module/VuFind/src/VuFind/Db/Table/UserList.php @@ -41,12 +41,23 @@ use VuFind\Exception\LoginRequired as LoginRequiredException, */ class UserList extends Gateway { + /** + * Session container for last list information. + * + * @var \Zend\Session\Container + */ + protected $session; + /** * Constructor + * + * @param \Zend\Session\Container $session Session container (must use same + * namespace as container provided to \VuFind\View\Helper\Root\UserList). */ - public function __construct() + public function __construct(\Zend\Session\Container $session) { parent::__construct('user_list', 'VuFind\Db\Row\UserList'); + $this->session = $session; } /** @@ -127,4 +138,16 @@ class UserList extends Gateway }; return $this->select($callback); } + + /** + * Construct the prototype for rows. + * + * @return object + */ + protected function initializeRowPrototype() + { + $prototype = parent::initializeRowPrototype(); + $prototype->setSession($this->session); + return $prototype; + } } diff --git a/module/VuFind/src/VuFind/ILS/Driver/Demo.php b/module/VuFind/src/VuFind/ILS/Driver/Demo.php index 62b0c56761728bd3228dec3c247fed9f916db8ce..402a2ca303e81e3030e78423f8fadc9215eb5af6 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Demo.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Demo.php @@ -110,12 +110,15 @@ class Demo extends AbstractBase * * @param \VuFind\Date\Converter $dateConverter Date converter object * @param SearchService $ss Search service + * @param SessionContainer $session Session container for persisting + * fake data to simulate consistency and reduce Solr hits */ public function __construct(\VuFind\Date\Converter $dateConverter, - SearchService $ss + SearchService $ss, SessionContainer $session ) { $this->dateConverter = $dateConverter; $this->searchService = $ss; + $this->session = $session; } /** @@ -142,10 +145,6 @@ class Demo extends AbstractBase if (isset($this->config['Failure_Probabilities'])) { $this->failureProbabilities = $this->config['Failure_Probabilities']; } - // Establish a namespace in the session for persisting fake data (to save - // on Solr hits): - $this->session = new SessionContainer('DemoDriver'); - if (isset($this->config['Holdings'])) { foreach ($this->config['Holdings'] as $id => $json) { foreach (json_decode($json, true) as $i => $status) { diff --git a/module/VuFind/src/VuFind/ILS/Driver/Factory.php b/module/VuFind/src/VuFind/ILS/Driver/Factory.php index 88c10df5398b76743d79fdd0f06d8335c34379f7..88a9924aaf8b32b1c5aa9350cfcf8ee6d0edc047 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Factory.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Factory.php @@ -79,9 +79,11 @@ class Factory */ public static function getDemo(ServiceManager $sm) { + $session = $sm->getServiceLocator() + ->get('VuFind\Session\OnDemandContainerFactory')->get('DemoDriver'); return new Demo( $sm->getServiceLocator()->get('VuFind\DateConverter'), - $sm->getServiceLocator()->get('VuFind\Search') + $sm->getServiceLocator()->get('VuFind\Search'), $session ); } diff --git a/module/VuFind/src/VuFind/Search/Factory/EdsBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/EdsBackendFactory.php index 1adbf08015280ad48cf0bde14862d4428f623372..d57c5c208901470e034e693dc3830b9da6edea41 100644 --- a/module/VuFind/src/VuFind/Search/Factory/EdsBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/EdsBackendFactory.php @@ -105,10 +105,13 @@ class EdsBackendFactory implements FactoryInterface { $auth = $this->serviceLocator->get('ZfcRbac\Service\AuthorizationService'); $isGuest = !$auth->isGranted('access.EDSExtendedResults'); + $session = new \Zend\Session\Container( + 'EBSCO', $this->serviceLocator->get('VuFind\SessionManager') + ); $backend = new Backend( $connector, $this->createRecordCollectionFactory(), $this->serviceLocator->get('VuFind\CacheManager')->getCache('object'), - new \Zend\Session\Container('EBSCO'), $this->edsConfig, $isGuest + $session, $this->edsConfig, $isGuest ); $backend->setAuthManager($this->serviceLocator->get('VuFind\AuthManager')); $backend->setLogger($this->logger); diff --git a/module/VuFind/src/VuFind/Search/Memory.php b/module/VuFind/src/VuFind/Search/Memory.php index 6c81d444974f147643cd1d4cee696d6a198bce14..b4f5ab03df876051b6b4c46b7080f4c06c8736f7 100644 --- a/module/VuFind/src/VuFind/Search/Memory.php +++ b/module/VuFind/src/VuFind/Search/Memory.php @@ -58,10 +58,9 @@ class Memory * * @param Container $session Session container for storing URLs (optional) */ - public function __construct($session = null) + public function __construct(Container $session) { - $this->session = (null === $session) - ? new Container('Search') : $session; + $this->session = $session; } /** diff --git a/module/VuFind/src/VuFind/Search/Options/Factory.php b/module/VuFind/src/VuFind/Search/Options/Factory.php index 4be559cf92b591062afe6c77289d9e796045651c..079782f6459c3169a236db8dd9985a2d2651d4bc 100644 --- a/module/VuFind/src/VuFind/Search/Options/Factory.php +++ b/module/VuFind/src/VuFind/Search/Options/Factory.php @@ -51,7 +51,9 @@ class Factory public static function getEDS(ServiceManager $sm) { $config = $sm->getServiceLocator()->get('VuFind\Config'); - $container = new \Zend\Session\Container('EBSCO'); + $container = new \Zend\Session\Container( + 'EBSCO', $sm->getServiceLocator()->get('VuFind\SessionManager') + ); // No API info in session? Re-establish connection: if (!isset($container->info)) { $backend = $sm->getServiceLocator()->get('VuFind\Search\BackendManager') diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php index 3f2415acf59fc12cfea484b34492dd41e2390452..c5194593923048e0e5cba245d02f868792a359e1 100644 --- a/module/VuFind/src/VuFind/Service/Factory.php +++ b/module/VuFind/src/VuFind/Service/Factory.php @@ -479,6 +479,18 @@ class Factory return $logger; } + /** + * Construct the on-demand session container factory. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Session\OnDemandContainerFactory + */ + public static function getOnDemandContainerFactory(ServiceManager $sm) + { + return new \VuFind\Session\OnDemandContainerFactory($sm); + } + /** * Construct the ProxyManager configuration. * @@ -675,6 +687,20 @@ class Factory return $manager; } + /** + * Construct the search memory helper. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Search\Memory + */ + public static function getSearchMemory(ServiceManager $sm) + { + return new \VuFind\Search\Memory( + new \Zend\Session\Container('Search', $sm->get('VuFind\SessionManager')) + ); + } + /** * Construct the Search\Options Plugin Manager. * @@ -776,31 +802,6 @@ class Factory ); } - /** - * Construct the Session Manager. - * - * @param ServiceManager $sm Service manager. - * - * @return \Zend\Session\SessionManager - */ - public static function getSessionManager(ServiceManager $sm) - { - $cookieManager = $sm->get('VuFind\CookieManager'); - $sessionConfig = new \Zend\Session\Config\SessionConfig(); - $options = [ - 'cookie_path' => $cookieManager->getPath(), - 'cookie_secure' => $cookieManager->isSecure() - ]; - $domain = $cookieManager->getDomain(); - if (!empty($domain)) { - $options['cookie_domain'] = $domain; - } - - $sessionConfig->setOptions($options); - - return new \Zend\Session\SessionManager($sessionConfig); - } - /** * Construct the Session Plugin Manager. * diff --git a/module/VuFind/src/VuFind/Session/ManagerFactory.php b/module/VuFind/src/VuFind/Session/ManagerFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..16c7ac2e74d8fa8bd6399a329922fcad0efc92d7 --- /dev/null +++ b/module/VuFind/src/VuFind/Session/ManagerFactory.php @@ -0,0 +1,145 @@ +<?php +/** + * Factory for instantiating Session Manager + * + * PHP version 5 + * + * Copyright (C) Villanova University 2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind + * @package Session_Handlers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\Session; +use Zend\ServiceManager\ServiceLocatorInterface; +use Zend\Session\SessionManager; + +/** + * Factory for instantiating Session Manager + * + * @category VuFind + * @package Session_Handlers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + * + * @codeCoverageIgnore + */ +class ManagerFactory implements \Zend\ServiceManager\FactoryInterface +{ + /** + * Build the options array. + * + * @param ServiceLocatorInterface $sm Service manager + * + * @return array + */ + protected function getOptions(ServiceLocatorInterface $sm) + { + $cookieManager = $sm->get('VuFind\CookieManager'); + $options = [ + 'cookie_path' => $cookieManager->getPath(), + 'cookie_secure' => $cookieManager->isSecure() + ]; + $domain = $cookieManager->getDomain(); + if (!empty($domain)) { + $options['cookie_domain'] = $domain; + } + return $options; + } + + /** + * Set up the session handler by retrieving all the pieces from the service + * manager and injecting appropriate dependencies. + * + * @param ServiceLocatorInterface $sm Service manager + * + * @return array + */ + protected function getHandler(ServiceLocatorInterface $sm) + { + // Load and validate session configuration: + $config = $sm->get('VuFind\Config')->get('config'); + if (!isset($config->Session->type)) { + throw new \Exception('Cannot initialize session; configuration missing'); + } + + $sessionPluginManager = $sm->get('VuFind\SessionPluginManager'); + $sessionHandler = $sessionPluginManager->get($config->Session->type); + $sessionHandler->setConfig($config->Session); + return $sessionHandler; + } + + /** + * According to the PHP manual, session_write_close should always be + * registered as a shutdown function when using an object as a session + * handler: http://us.php.net/manual/en/function.session-set-save-handler.php + * + * This method sets that up. + * + * @param SessionManager $sessionManager Session manager instance + * + * @return void + */ + protected function registerShutdownFunction(SessionManager $sessionManager) + { + register_shutdown_function( + function () use ($sessionManager) { + // If storage is immutable, the session is already closed: + if (!$sessionManager->getStorage()->isImmutable()) { + $sessionManager->writeClose(); + } + } + ); + } + + /** + * Create service + * + * @param ServiceLocatorInterface $sm Service manager + * + * @return mixed + */ + public function createService(ServiceLocatorInterface $sm) + { + // Build configuration: + $sessionConfig = new \Zend\Session\Config\SessionConfig(); + $sessionConfig->setOptions($this->getOptions($sm)); + + // Build session manager and attach handler: + $sessionManager = new SessionManager($sessionConfig); + $sessionManager->setSaveHandler($this->getHandler($sm)); + + // Start up the session: + $sessionManager->start(); + + // Check if we need to immediately stop it based on the settings object + // (which may have been informed by a controller that sessions should not + // be written as part of the current process): + $settings = $sm->get('VuFind\Session\Settings'); + if ($settings->setSessionManager($sessionManager)->isWriteDisabled()) { + $sessionManager->writeClose(); + } else { + // If the session is not disabled, we should set up the normal + // shutdown function: + $this->registerShutdownFunction($sessionManager); + } + + return $sessionManager; + } +} diff --git a/module/VuFind/src/VuFind/Session/OnDemandContainerFactory.php b/module/VuFind/src/VuFind/Session/OnDemandContainerFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..e49ecf440fea1028d268452655292144260f4929 --- /dev/null +++ b/module/VuFind/src/VuFind/Session/OnDemandContainerFactory.php @@ -0,0 +1,83 @@ +<?php +/** + * Factory for on-demand session containers. This allows us to create a session + * container but not start up the session unless it is actually accessed. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind + * @package Session_Handlers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\Session; +use Zend\ServiceManager\ServiceManager; + +/** + * Factory for on-demand session containers. This allows us to create a session + * container but not start up the session unless it is actually accessed. + * + * @category VuFind + * @package Session_Handlers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class OnDemandContainerFactory +{ + /** + * Service manager + * + * @var ServiceManager + */ + protected $sm; + + /** + * Constructor + * + * @param ServiceManager $sm Service manager + */ + public function __construct(ServiceManager $sm) + { + $this->sm = $sm; + } + + /** + * Get a specific named container. + * + * @param string $namespace Namespace for container. + * + * @return \Zend\Session\Container + */ + public function get($namespace) + { + $sm = $this->sm; + $callback = function (& $wrapped, $proxy) use ($namespace, $sm) { + // Generate wrapped object: + $manager = $sm->get('VuFind\SessionManager'); + $wrapped = new \Zend\Session\Container($namespace, $manager); + + // Indicate that initialization is complete to avoid reinitialization: + $proxy->setProxyInitializer(null); + }; + $cfg = $sm->get('VuFind\ProxyConfig'); + $factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory($cfg); + return $factory->createProxy('Zend\Session\Container', $callback); + } +} diff --git a/module/VuFind/src/VuFind/Session/Settings.php b/module/VuFind/src/VuFind/Session/Settings.php new file mode 100644 index 0000000000000000000000000000000000000000..b3cb072f47225b46f3c67480c5c876b262e9b513 --- /dev/null +++ b/module/VuFind/src/VuFind/Session/Settings.php @@ -0,0 +1,100 @@ +<?php +/** + * Container for session settings, allowing those settings to be configured + * "just in case" they are needed, without invoking the heavy weight of + * instantiating the session itself. See \VuFind\Session\ManagerFactory for + * details on the use of this object. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind + * @package Session_Handlers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\Session; +use Zend\Session\SessionManager; + +/** + * Container for session settings, allowing those settings to be configured + * "just in case" they are needed, without invoking the heavy weight of + * instantiating the session itself. See \VuFind\Session\ManagerFactory for + * details on the use of this object. + * + * @category VuFind + * @package Session_Handlers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class Settings +{ + /** + * Have session writes been disabled? + * + * @var bool + */ + protected $disableWrite = false; + + /** + * Session manager (if instantiated) + * + * @var SessionManager + */ + protected $manager = null; + + /** + * Disable session writes after this point in time. + * + * @return void + */ + public function disableWrite() + { + // Set the flag + $this->disableWrite = true; + + // If the session manager is already instantiated, close it! + if (null !== $this->manager) { + $this->manager->writeClose(); + } + } + + /** + * Have session writes been disabled? + * + * @return bool + */ + public function isWriteDisabled() + { + return $this->disableWrite; + } + + /** + * Set a session manager instance. + * + * @param SessionManager $sessionManager Session manager + * + * @return Settings + */ + public function setSessionManager(SessionManager $sessionManager) + { + $this->manager = $sessionManager; + return $this; + } +} diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php index 255ebf8877004c95bd4e1c91eecc3084350d2dad..161cc89d78741179c5a7402780b37c383ca35187 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php @@ -525,8 +525,10 @@ class Factory */ public static function getUserList(ServiceManager $sm) { + $sessionManager = $sm->getServiceLocator()->get('VuFind\SessionManager'); + $session = new \Zend\Session\Container('List', $sessionManager); $capabilities = $sm->getServiceLocator()->get('VuFind\AccountCapabilities'); - return new UserList($capabilities->getListSetting()); + return new UserList($session, $capabilities->getListSetting()); } /** diff --git a/module/VuFind/src/VuFind/View/Helper/Root/UserList.php b/module/VuFind/src/VuFind/View/Helper/Root/UserList.php index 54e1ec23eb3cfa154197a8b0cc476f0fe38caac8..85f5c1fe823f113efd2d0740cd493141b00895bc 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/UserList.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/UserList.php @@ -46,14 +46,24 @@ class UserList extends AbstractHelper */ protected $mode; + /** + * Session container for last list information. + * + * @var \Zend\Session\Container + */ + protected $session; + /** * Constructor * - * @param string $mode List mode (enabled or disabled) + * @param \Zend\Session\Container $session Session container (must use same + * namespace as container provided to \VuFind\Db\Table\UserList) + * @param string $mode List mode (enabled or disabled) */ - public function __construct($mode = 'enabled') + public function __construct(\Zend\Session\Container $session, $mode = 'enabled') { $this->mode = $mode; + $this->session = $session; } /** @@ -73,6 +83,6 @@ class UserList extends AbstractHelper */ public function lastUsed() { - return UserListRow::getLastUsed(); + return isset($this->session->lastUsed) ? $this->session->lastUsed : null; } } diff --git a/module/VuFind/src/VuFindTest/Unit/DbTestCase.php b/module/VuFind/src/VuFindTest/Unit/DbTestCase.php index 9026db3c46fd2a848227cce806dc475702fbd911..3570cd7f7afcb83ede23b9655008d13e514f7835 100644 --- a/module/VuFind/src/VuFindTest/Unit/DbTestCase.php +++ b/module/VuFind/src/VuFindTest/Unit/DbTestCase.php @@ -63,12 +63,17 @@ abstract class DbTestCase extends TestCase 'factories' => [ 'resource' => 'VuFind\Db\Table\Factory::getResource', 'user' => 'VuFind\Db\Table\Factory::getUser', + 'userlist' => 'VuFind\Db\Table\Factory::getUserList', ] ] ) ); $factory->setServiceLocator($sm); $sm->setService('VuFind\DbTablePluginManager', $factory); + $sm->setService( + 'VuFind\SessionManager', + $this->getMock('Zend\Session\SessionManager') + ); // Override the configuration so PostgreSQL tests can work: $sm->setAllowOverride(true); diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ChoiceAuthTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ChoiceAuthTest.php index 04a22bfd38642112795fbdd5adf611bfc8d09ea9..dc1a3aa942168df2c3f744855f1873cc58637b6a 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ChoiceAuthTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ChoiceAuthTest.php @@ -51,7 +51,7 @@ class ChoiceAuthTest extends \VuFindTest\Unit\TestCase */ public function testBadConfiguration() { - $ca = new ChoiceAuth(); + $ca = new ChoiceAuth($this->getSessionContainer()); $ca->setConfig(new Config([])); } @@ -65,7 +65,7 @@ class ChoiceAuthTest extends \VuFindTest\Unit\TestCase */ public function testMissingPluginManager() { - $ca = new ChoiceAuth(); + $ca = new ChoiceAuth($this->getSessionContainer()); $ca->getPluginManager(); } @@ -145,12 +145,11 @@ class ChoiceAuthTest extends \VuFindTest\Unit\TestCase */ public function testLogout() { - $session = new \Zend\Session\Container('ChoiceAuth'); - $session->auth_method = 'Shibboleth'; + $session = $this->getSessionContainer('Shibboleth'); $pm = $this->getMockPluginManager(); $shib = $pm->get('Shibboleth'); $shib->expects($this->once())->method('logout')->with($this->equalTo('http://foo'))->will($this->returnValue('http://bar')); - $ca = $this->getChoiceAuth($pm); + $ca = $this->getChoiceAuth($pm, $session); $this->assertEquals('http://bar', $ca->logout('http://foo')); } @@ -200,17 +199,37 @@ class ChoiceAuthTest extends \VuFindTest\Unit\TestCase $this->assertFalse($ca->supportsPasswordChange()); } + /** + * Get a dummy session container. + * + * @param string $method Auth method to set in container (null for none). + * + * @return \Zend\Session\Container + */ + protected function getSessionContainer($method = null) + { + $mock = $this->getMockBuilder('Zend\Session\Container') + ->setMethods(['__get', '__isset', '__set', '__unset']) + ->disableOriginalConstructor()->getMock(); + if ($method) { + $mock->expects($this->any())->method('__isset')->with($this->equalTo('auth_method'))->will($this->returnValue(true)); + $mock->expects($this->any())->method('__get')->with($this->equalTo('auth_method'))->will($this->returnValue($method)); + } + return $mock; + } + /** * Get a ChoiceAuth object. * - * @param PluginManager $pm Plugin manager - * @param string $strategies Strategies setting + * @param PluginManager $pm Plugin manager + * @param \Zend\Session\Container $session Session container + * @param string $strategies Strategies setting * * @return ChoiceAuth */ - protected function getChoiceAuth($pm = null, $strategies = 'Database,Shibboleth') + protected function getChoiceAuth($pm = null, $session = null, $strategies = 'Database,Shibboleth') { - $ca = new ChoiceAuth(); + $ca = new ChoiceAuth($session ?: $this->getSessionContainer()); $ca->setConfig( new Config(['ChoiceAuth' => ['choice_order' => $strategies]]) ); diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php index 0cc636563a4b00b7ce3f11555bb2fe09eeceebba..e4cac9004281e2d5534b977b4108834de9174a0a 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php @@ -475,8 +475,15 @@ class ManagerTest extends \VuFindTest\Unit\TestCase $userArray->append($user); $table->expects($this->once())->method('select')->with($this->equalTo(['id' => 'foo']))->will($this->returnValue($userArray->getIterator())); $manager = $this->getManager([], $table); - $session = $this->getProperty($manager, 'session'); - $session->userId = 'foo'; + + // Fake the session inside the manager: + $mockSession = $this->getMockBuilder('Zend\Session\Container') + ->setMethods(['__get', '__isset', '__set', '__unset']) + ->disableOriginalConstructor()->getMock(); + $mockSession->expects($this->any())->method('__isset')->with($this->equalTo('userId'))->will($this->returnValue(true)); + $mockSession->expects($this->any())->method('__get')->with($this->equalTo('userId'))->will($this->returnValue('foo')); + $this->setProperty($manager, 'session', $mockSession); + $this->assertEquals($user, $manager->isLoggedIn()); } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/FollowupTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/FollowupTest.php index 1fb5a7dad0162afe20473eeb6d349c3d55ad4477..41302f944683a8f15337a74ed735242f99beb5a4 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/FollowupTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/FollowupTest.php @@ -30,6 +30,7 @@ namespace VuFindTest\Controller\Plugin; use VuFind\Controller\Plugin\Followup; use VuFindTest\Unit\TestCase as TestCase; +use Zend\Session\Container; /** * Followup controller plugin tests. @@ -49,7 +50,7 @@ class FollowupTest extends TestCase */ public function testClear() { - $f = new Followup(); + $f = new Followup(new Container('test')); $f->setController($this->getMockController()); $this->assertFalse($f->clear('url')); // nothing to clear yet $f->store(); @@ -64,7 +65,7 @@ class FollowupTest extends TestCase */ public function testRetrieve() { - $f = new Followup(); + $f = new Followup(new Container('test')); $f->setController($this->getMockController()); $f->store(); // standard controller-provided URL retrieval: @@ -82,7 +83,7 @@ class FollowupTest extends TestCase */ public function testRetrieveAndClear() { - $f = new Followup(); + $f = new Followup(new Container('test')); $f->store(['foo' => 'bar'], 'baz'); $this->assertEquals('bar', $f->retrieveAndClear('foo')); $this->assertEquals('baz', $f->retrieveAndClear('url')); diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php index c0e416a06b9fd3d5f39a9e4871ec00d5c779dca5..0bf9127024d3d95cb17733e2a74e59345985d3c6 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php @@ -30,6 +30,7 @@ namespace VuFindTest\Controller\Plugin; use VuFind\Controller\Plugin\ResultScroller; use VuFindTest\Unit\TestCase as TestCase; +use Zend\Session\Container; /** * ResultScroller controller plugin tests. @@ -49,7 +50,7 @@ class ResultScrollerTest extends TestCase */ public function testDisabled() { - $plugin = new ResultScroller(false); + $plugin = new ResultScroller(new Container('test'), false); $results = $this->getMockResults(); $this->assertFalse($plugin->init($results)); $expected = [ @@ -191,7 +192,9 @@ class ResultScrollerTest extends TestCase */ protected function getMockResultScroller($results = null, $methods = ['restoreLastSearch', 'rememberSearch']) { - $mock = $this->getMock('VuFind\Controller\Plugin\ResultScroller', $methods); + $mock = $this->getMock( + 'VuFind\Controller\Plugin\ResultScroller', $methods, [new Container('test')] + ); if (in_array('restoreLastSearch', $methods) && null !== $results) { $mock->expects($this->any())->method('restoreLastSearch')->will($this->returnValue($results)); } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/DemoTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/DemoTest.php index b49e814fe6881dd1fc8d7038b3285b564c4808c3..7ea05bc578326fbdf83470ccd9e8631c990eb461 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/DemoTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/DemoTest.php @@ -53,8 +53,11 @@ class DemoTest extends \VuFindTest\Unit\TestCase */ public function setUp() { + $session = $this->getMockBuilder('Zend\Session\Container') + ->disableOriginalConstructor()->getMock(); $this->driver = new Demo( - new \VuFind\Date\Converter(), $this->getMock('VuFindSearch\Service') + new \VuFind\Date\Converter(), $this->getMock('VuFindSearch\Service'), + $session ); $this->driver->init(); } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php index e3f7404c8ff3d10efcd4686317cc5b7fd7725cf8..6bfab36ec6f4f8724af148575b0bf7f23005975e 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php @@ -2497,26 +2497,39 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase return $sm; } + /** + * Get a mock Demo driver + * + * @return \VuFind\ILS\Driver\Demo + */ + protected function getMockDemoDriver($methods) + { + $session = $this->getMockBuilder('Zend\Session\Container') + ->disableOriginalConstructor()->getMock(); + return $this->getMock( + "VuFind\ILS\Driver\Demo", $methods, + [ + new \VuFind\Date\Converter(), + $this->getMock('VuFindSearch\Service'), + $session + ] + ); + } + /** * Get a mock driver * * @param string $type Type of driver to make * @param array $methods Array of methods to stub * - * @return \VuFind\ILS\Driver\$type + * @return \VuFind\ILS\Driver\AbstractBase */ protected function getMockILS($type, $methods = null) { $mock = null; try { if ($type == 'Demo') { - $mock = $this->getMock( - "VuFind\ILS\Driver\\$type", $methods, - [ - new \VuFind\Date\Converter(), - $this->getMock('VuFindSearch\Service') - ] - ); + $mock = $this->getMockDemoDriver($methods); } else { $mock = $this->getMock( "VuFind\ILS\Driver\\$type", $methods, diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Search/MemoryTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/MemoryTest.php index bcbc48cd1e6c4ae7682541c12034403d76e6cfed..28ea54b45b342065eae907d9509a01b6a30321f1 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Search/MemoryTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/MemoryTest.php @@ -30,6 +30,7 @@ namespace VuFindTest\Search; use VuFind\Search\Memory; use VuFindTest\Unit\TestCase as TestCase; +use Zend\Session\Container; /** * Memory unit tests. @@ -49,7 +50,7 @@ class MemoryTest extends TestCase */ public function testBasicMemory() { - $mem = new Memory(); + $mem = new Memory(new Container('test')); $this->assertEquals(null, $mem->retrieveSearch()); $url = 'http://test'; $mem->rememberSearch($url); @@ -63,7 +64,7 @@ class MemoryTest extends TestCase */ public function testForgetting() { - $mem = new Memory(); + $mem = new Memory(new Container('test')); $url = 'http://test'; $mem->rememberSearch($url); $this->assertEquals($url, $mem->retrieveSearch()); @@ -78,7 +79,7 @@ class MemoryTest extends TestCase */ public function testEmptyURL() { - $mem = new Memory(); + $mem = new Memory(new Container('test')); $mem->rememberSearch(''); $this->assertEquals(null, $mem->retrieveSearch()); } @@ -90,7 +91,7 @@ class MemoryTest extends TestCase */ public function testDisable() { - $mem = new Memory(); + $mem = new Memory(new Container('test')); $url = 'http://test'; $mem->rememberSearch($url); $this->assertEquals($url, $mem->retrieveSearch());