Bug 40424: Simplify existing code - preparation

I wanted to isolate the changes for the query-in-body handling and it
made sense to refactor this dupicated code at the same time. So I add
this patch for tidying the area in preparation for the other part.

Duplicated code gets simplified.

To test:
1. Apply the unit tests patch
2. Run:
   $ ktd --shell
  k$ prove t/Koha/REST/Plugin/Query.t \
           t/db_dependent/api/v1/*.t \
           t/db_dependent/Koha/REST/Plugin/
=> SUCCESS: Tests pass!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 710bf4bb1b)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Tomas Cohen Arazi 2025-07-17 11:34:14 -03:00 committed by Paul Derscheid
parent c7251cf7f5
commit d81809b4ba
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 9 additions and 17 deletions

View File

@ -214,7 +214,10 @@ controller, and thus shouldn't be called twice in it.
);
my $query_params;
if ( defined $reserved_params->{q}
my $q_param = $reserved_params->{q};
if ( $q_param
|| defined $reserved_params->{query} )
{
@ -231,23 +234,12 @@ controller, and thus shouldn't be called twice in it.
push @query_params_array, $json->decode($query);
}
if ( ref( $reserved_params->{q} ) eq 'ARRAY' ) {
# The q parameter can be an array if multiple passed
$q_param = [$q_param]
unless ref($q_param) eq 'ARRAY';
# q is defined as multi => JSON::Validator generates an array
foreach my $q ( @{ $reserved_params->{q} } ) {
if ($q) { # skip if exists but is empty
foreach my $qf ( @{$query_fixers} ) {
$q = $qf->($q);
}
push @query_params_array, $json->decode($q);
}
}
} else {
# objects.search called outside OpenAPI context
# might be a hashref
if ( $reserved_params->{q} ) {
my $q = $reserved_params->{q};
foreach my $q ( @{$q_param} ) {
if ($q) { # skip if exists but is empty
foreach my $qf ( @{$query_fixers} ) {
$q = $qf->($q);
}