From 244a4d63cbc550227785aadd07ae75fc3dbf1598 Mon Sep 17 00:00:00 2001 From: Pedro Amorim 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. Signed-off-by: Martin Renvoize Signed-off-by: Laura Escamilla --- Koha/Illbackend.pm | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/Koha/Illbackend.pm b/Koha/Illbackend.pm index cb27e21154..df29e970a5 100644 --- a/Koha/Illbackend.pm +++ b/Koha/Illbackend.pm @@ -48,6 +48,8 @@ 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. @@ -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.30.2