From 9c4c4a42f416cd57763953667916e72005d823ad Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 25 Apr 2019 11:23:52 -0400 Subject: [PATCH] Bug fix: reset page number when switching library cards. - Prevents fatal error when switching from a deep page of checked out items to an account that has fewer pages of results. --- .../Controller/LibraryCardsController.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/module/VuFind/src/VuFind/Controller/LibraryCardsController.php b/module/VuFind/src/VuFind/Controller/LibraryCardsController.php index 909c51aa604..dbc47d66067 100644 --- a/module/VuFind/src/VuFind/Controller/LibraryCardsController.php +++ b/module/VuFind/src/VuFind/Controller/LibraryCardsController.php @@ -178,6 +178,21 @@ class LibraryCardsController extends AbstractBase ); } + /** + * When redirecting after selecting a library card, adjust the URL to make + * sure it will work correctly. + * + * @param string $url URL to adjust + * + * @return string + */ + protected function adjustCardRedirectUrl($url) + { + // If there is pagination in the URL, reset it to page 1, since the + // new card may have a different number of pages of data: + return preg_replace('/([&?]page)=[0-9]+/', '$1=1', $url); + } + /** * Activates a library card * @@ -215,7 +230,7 @@ class LibraryCardsController extends AbstractBase $this->setFollowupUrlToReferer(); if ($url = $this->getFollowupUrl()) { $this->clearFollowupUrl(); - return $this->redirect()->toUrl($url); + return $this->redirect()->toUrl($this->adjustCardRedirectUrl($url)); } return $this->redirect()->toRoute('myresearch-home'); } -- GitLab