From 22a6e18afd02772c46a4bf7030091c719c2bdbf2 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 27 Jul 2023 12:25:20 +0100 Subject: [PATCH] Bug 34223: (follow-up) Restore status_alias handling By reducing the original call to all distinct 'status' we also removed the status_alias combinations. This patch adds an additional distinct query to fetch all 'status_alias' and add them to the returned data structure. --- Koha/Illbackend.pm | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/Koha/Illbackend.pm b/Koha/Illbackend.pm index 017619febb..df29e970a5 100644 --- a/Koha/Illbackend.pm +++ b/Koha/Illbackend.pm @@ -48,10 +48,12 @@ Return a list of existing ILL statuses sub existing_statuses { my ( $self, $backend_id ) = @_; + my @data; + # NOTE: This query fetches all distinct status's found in the database for this backend. # We need the 'status' field for obvious reasons, the 'backend' field is required to not # throw 'Koha::Exceptions::Ill::InvalidBackendId' when we're converting to a Koha object. - # Finally, to get around 'ONLY_FULL_GROUP_BY', we have to be explicit about which + # Finally, to get around 'ONLY_FULL_GROUP_BY', we have to be explicit about which # 'request_id' we want to return, hense the 'MAX' call. my $ill_requests = Koha::Illrequests->search( { backend => $backend_id }, @@ -61,19 +63,38 @@ sub existing_statuses { group_by => [qw/status backend/], } ); + while ( my $request = $ill_requests->next ) { + my $status_data = $request->strings_map; - my @data; - while (my $request = $ill_requests->next) { + if ( $status_data->{status} ) { + push @data, { + $status_data->{status}->{str} ? ( str => $status_data->{status}->{str} ) + : $status_data->{status}->{code} ? ( str => $status_data->{status}->{code} ) + : (), + $status_data->{status}->{code} ? ( code => $status_data->{status}->{code} ) : (), + }; + } + } + + # Now do the same to get all status_aliases + $ill_requests = Koha::Illrequests->search( + { backend => $backend_id }, + { + select => [ 'status_alias', \'MAX(illrequest_id)', 'backend' ], + as => [qw/ status_alias illrequest_id backend /], + group_by => [qw/status_alias backend/], + } + ); + while ( my $request = $ill_requests->next ) { my $status_data = $request->strings_map; - foreach my $status_class ( qw(status_alias status) ){ - if ($status_data->{$status_class}){ - push @data, { - $status_data->{$status_class}->{str} ? (str => $status_data->{$status_class}->{str}) : - $status_data->{$status_class}->{code} ? (str => $status_data->{$status_class}->{code}) : (), - $status_data->{$status_class}->{code} ? (code => $status_data->{$status_class}->{code}) : (), - } - } + if ( $status_data->{status_alias} ) { + push @data, { + $status_data->{status_alias}->{str} ? ( str => $status_data->{status_alias}->{str} ) + : $status_data->{status_alias}->{code} ? ( str => $status_data->{status_alias}->{code} ) + : (), + $status_data->{status_alias}->{code} ? ( code => $status_data->{status_alias}->{code} ) : (), + }; } } -- 2.41.0