From 27fde89dd98cabeed265e8c9b431e28ec37bab51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Siiri=20Yl=C3=B6nen?= Date: Wed, 4 Dec 2024 12:34:49 +0200 Subject: [PATCH] Comment to route and initiated cache array in construct. --- module/Finna/config/module.config.php | 1 + .../src/Finna/Controller/LibraryCardsController.php | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/module/Finna/config/module.config.php b/module/Finna/config/module.config.php index 85db938465e..ff5415f110c 100644 --- a/module/Finna/config/module.config.php +++ b/module/Finna/config/module.config.php @@ -1160,6 +1160,7 @@ ], ], ]; +// @deprecated, use librarycards-displaybarcode $config['router']['routes']['barcode-show'] = [ 'type' => 'Laminas\Router\Http\Segment', 'options' => [ diff --git a/module/Finna/src/Finna/Controller/LibraryCardsController.php b/module/Finna/src/Finna/Controller/LibraryCardsController.php index af8d26ac0d9..8d35810045e 100644 --- a/module/Finna/src/Finna/Controller/LibraryCardsController.php +++ b/module/Finna/src/Finna/Controller/LibraryCardsController.php @@ -66,6 +66,7 @@ public function __construct( protected SessionContainer $session, ) { parent::__construct($sm); + $this->session->LibraryCards ??= []; } /** @@ -920,14 +921,14 @@ public function displayBarcodeAction(): mixed } $userCardService = $this->getDbService(UserCardServiceInterface::class); $card = $userCardService->getOrCreateLibraryCard($user, $id); - if (isset($this->session->LibraryCards[$id])) { - $barcode = $this->session->LibraryCards[$id]; - return $this->createViewModel(['code' => $barcode]); - } $username = $card->getCatUsername(); if (str_contains($username, '.')) { [, $username] = explode('.', $username, 2); } + if (isset($this->session->LibraryCards[$username . '|' . $id])) { + $barcode = $this->session->LibraryCards[$username . '|' . $id]; + return $this->createViewModel(['code' => $barcode]); + } $catalog = $this->getILS(); $auth = $this->getILSAuthenticator(); if ($card->getCatUsername() === $user->getCatUsername()) { @@ -949,7 +950,7 @@ public function displayBarcodeAction(): mixed } } $barcode ??= $username; - $this->session->LibraryCards[$id] = $barcode; + $this->session->LibraryCards[$username . '|' . $id] = $barcode; return $this->createViewModel(['code' => $barcode]); } catch (\Exception) { $this->flashMessenger()->addErrorMessage('An error has occurred');