Bug 21941: Fix GROUP BY in circ/reserveratios.pl

When using strict_sql_modes, the Hold ratios page causes an Incorrect
GROUP BY error and returns an Error 500.

This patch removes uncessary columns from the database query and adds
the biblio columns to the GROUP BY statement, so they can be selected.
Since it's already grouped by biblionumber, it should not cause any
additional rows to be created.

Test plan:
1. Make sure that strict_sql_modes is enabled in the koha-conf.xml
   file.
2. Place at least one hold on a book.
3. Go to Circulation and select Hold ratios.
4. Observe that you get an Error 500.
5. Apply patch.
6. Repeat step 3.
7. Observe that you can view the page.
8. If the table is empty, change the ratio to 1.
9. Sign off.

Sponsored-by: Lund University Library
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Kevin Carnes 2026-02-24 13:22:01 +01:00 committed by Lucas Gass
parent 3a6a79a607
commit ea4600476e
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 5 additions and 17 deletions

View File

@ -98,13 +98,7 @@ my $include_aqorders_qty_join =
my $nfl_comparison = $include_ordered ? '<=' : '='; my $nfl_comparison = $include_ordered ? '<=' : '=';
my $sus_comparison = $include_suspended ? '<=' : '<'; my $sus_comparison = $include_suspended ? '<=' : '<';
my $strsth = "SELECT reservedate, my $strsth = "SELECT reserves.biblionumber,
reserves.borrowernumber as borrowernumber,
reserves.biblionumber,
reserves.branchcode as branch,
items.holdingbranch,
items.itemcallnumber,
items.itemnumber,
GROUP_CONCAT(DISTINCT items.itemcallnumber GROUP_CONCAT(DISTINCT items.itemcallnumber
ORDER BY items.itemnumber SEPARATOR '|') as listcall, ORDER BY items.itemnumber SEPARATOR '|') as listcall,
GROUP_CONCAT(DISTINCT homebranch GROUP_CONCAT(DISTINCT homebranch
@ -117,8 +111,6 @@ my $strsth = "SELECT reservedate,
ORDER BY items.itemnumber SEPARATOR '|') as l_itype, ORDER BY items.itemnumber SEPARATOR '|') as l_itype,
GROUP_CONCAT(DISTINCT items.ccode GROUP_CONCAT(DISTINCT items.ccode
ORDER BY items.ccode SEPARATOR '|') as l_ccode, ORDER BY items.ccode SEPARATOR '|') as l_ccode,
reserves.found,
biblio.title, biblio.title,
biblio.subtitle, biblio.subtitle,
biblio.medium, biblio.medium,
@ -142,7 +134,10 @@ if ( C4::Context->preference('IndependentBranches') ) {
push @query_params, C4::Context->userenv->{'branch'}; push @query_params, C4::Context->userenv->{'branch'};
} }
$strsth .= " GROUP BY reserves.biblionumber ORDER BY reservecount DESC"; $strsth .= " GROUP BY reserves.biblionumber, biblio.title, biblio.subtitle,
biblio.medium, biblio.part_number, biblio.part_name, biblio.author
ORDER BY reservecount DESC
";
$template->param( sql => $strsth ); $template->param( sql => $strsth );
my $sth = $dbh->prepare($strsth); my $sth = $dbh->prepare($strsth);
@ -156,22 +151,15 @@ while ( my $data = $sth->fetchrow_hashref ) {
push( push(
@reservedata, @reservedata,
{ {
reservedate => $data->{reservedate},
priority => $data->{priority},
name => $data->{borrower},
title => $data->{title}, title => $data->{title},
subtitle => $data->{subtitle}, subtitle => $data->{subtitle},
medium => $data->{medium}, medium => $data->{medium},
part_number => $data->{part_number}, part_number => $data->{part_number},
part_name => $data->{part_name}, part_name => $data->{part_name},
author => $data->{author}, author => $data->{author},
itemnum => $data->{itemnumber},
biblionumber => $data->{biblionumber}, biblionumber => $data->{biblionumber},
holdingbranch => $data->{holdingbranch},
homebranch_list => [ split( '\|', $data->{homebranch_list} ) ], homebranch_list => [ split( '\|', $data->{homebranch_list} ) ],
holdingbranch_list => [ split( '\|', $data->{holdingbranch_list} ) ], holdingbranch_list => [ split( '\|', $data->{holdingbranch_list} ) ],
branch => $data->{branch},
itemcallnumber => $data->{itemcallnumber},
location => [ split( '\|', $data->{l_location} ) ], location => [ split( '\|', $data->{l_location} ) ],
itype => [ split( '\|', $data->{l_itype} ) ], itype => [ split( '\|', $data->{l_itype} ) ],
ccode => [ split( '\|', $data->{l_ccode} ) ], ccode => [ split( '\|', $data->{l_ccode} ) ],