From 3e03e4cdfda5c0067f5c876868782bd95d1c2b66 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 22 Aug 2024 07:14:07 -0400 Subject: [PATCH 1/3] Fix query to select circulation rules for Koha #2008 Within Koha circulation rules are selected by branchcode, categorycode, and itemtype in that order where precedence takes the more specific rule over the less specific rule. This can be seen in the Koha code here: https://git.koha-community.org/Koha-community/Koha/src/branch/main/Koha/CirculationRules.pm#L275 Aspen attempts to replicate this but has a flaw. The problem only comes into play if the query ends up selecting multiple rules. Koha will always select first rule of the results, but Aspen will always select the last rule of the results. Closes Aspen-Discovery/aspen-discovery#2008 --- code/web/Drivers/Koha.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/code/web/Drivers/Koha.php b/code/web/Drivers/Koha.php index 92a4e51902..b1db2f1570 100644 --- a/code/web/Drivers/Koha.php +++ b/code/web/Drivers/Koha.php @@ -539,12 +539,16 @@ public function getCheckouts(User $patron): array { $circulationRulesForCheckout = []; /** @noinspection SqlResolve */ /** @noinspection SqlDialectInspection */ - $circulationRulesSql = "SELECT * FROM circulation_rules where (categorycode IN ('$patronType', '*') OR categorycode IS NULL) and (itemtype IN('$itemType', '*') OR itemtype is null) and (branchcode IN ('$checkoutBranch', '*') OR branchcode IS NULL) order by branchcode desc, categorycode desc, itemtype desc"; + $circulationRulesSql = " + SELECT * FROM circulation_rules + WHERE (categorycode IN ('$patronType', '*') OR categorycode IS NULL) + AND (itemtype IN('$itemType', '*') OR itemtype is null) + AND (branchcode IN ('$checkoutBranch', '*') OR branchcode IS NULL) + ORDER BY branchcode desc, categorycode desc, itemtype desc LIMIT 1"; $circulationRulesRS = mysqli_query($this->dbConnection, $circulationRulesSql); if ($circulationRulesRS !== false) { - while ($circulationRulesRow = $circulationRulesRS->fetch_assoc()) { - $circulationRulesForCheckout[] = $circulationRulesRow; - } + $circulationRulesRow = $circulationRulesRS->fetch_assoc(); + $circulationRulesForCheckout[] = $circulationRulesRow; $circulationRulesRS->close(); } $timer->logTime("Load circulation rules for checkout"); From 440b77133e9309ea96f39f5ab68949ec9ffda3e3 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 22 Aug 2024 07:18:42 -0400 Subject: [PATCH 2/3] Update release notes #2008 --- code/web/release_notes/24.09.00.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/code/web/release_notes/24.09.00.MD b/code/web/release_notes/24.09.00.MD index 78591c86f7..77d81a8a9e 100644 --- a/code/web/release_notes/24.09.00.MD +++ b/code/web/release_notes/24.09.00.MD @@ -132,6 +132,7 @@ - Remove superfluous loop in Koha driver function updateHomeLibrary #1968 (*KMH*) - Hide empty item groups for volume-level holds in Koha (*KMH*) - Remove old pre-production Koha volumes code (*KMH*) +- Fix query to select circulation rules for Koha (*KMH*) ### GitHub Actions - Add GitHub Actions to check pull requests for release notes (*KMH*) From 7c482524dbe296ea34f36279190cb6153abbdbce Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 22 Aug 2024 07:26:40 -0400 Subject: [PATCH 3/3] Indent the query properly #2008 --- code/web/Drivers/Koha.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/code/web/Drivers/Koha.php b/code/web/Drivers/Koha.php index b1db2f1570..6886add4ec 100644 --- a/code/web/Drivers/Koha.php +++ b/code/web/Drivers/Koha.php @@ -540,11 +540,12 @@ public function getCheckouts(User $patron): array { /** @noinspection SqlResolve */ /** @noinspection SqlDialectInspection */ $circulationRulesSql = " - SELECT * FROM circulation_rules - WHERE (categorycode IN ('$patronType', '*') OR categorycode IS NULL) - AND (itemtype IN('$itemType', '*') OR itemtype is null) - AND (branchcode IN ('$checkoutBranch', '*') OR branchcode IS NULL) - ORDER BY branchcode desc, categorycode desc, itemtype desc LIMIT 1"; + SELECT * FROM circulation_rules + WHERE (categorycode IN ('$patronType', '*') OR categorycode IS NULL) + AND (itemtype IN('$itemType', '*') OR itemtype is null) + AND (branchcode IN ('$checkoutBranch', '*') OR branchcode IS NULL) + ORDER BY branchcode desc, categorycode desc, itemtype desc LIMIT 1 + "; $circulationRulesRS = mysqli_query($this->dbConnection, $circulationRulesSql); if ($circulationRulesRS !== false) { $circulationRulesRow = $circulationRulesRS->fetch_assoc();