From c1f3cd520aa11876a027867a8c22973ccc9a205d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 1 Aug 2022 08:14:27 +0200 Subject: [PATCH] Bug 31158: (bug 23991 follow-up) Fix suggestion search by dates Search suggestions by date is broken, we don't remove the '_from' CGI params for the DBIC query DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Unknown column 'suggesteddate_from' in 'where clause' at /kohadevbox/koha/Koha/Objects.pm line 394 at /usr/share/perl5/DBIx/Class/Exception.pm line 77 Test plan: Create some suggestions, search for them using date range (suggested date, managed date and accepted date) Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- suggestion/suggestion.pl | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index c38367256f..e0c571b8aa 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -384,25 +384,20 @@ if ($op=~/else/) { # filter on date fields foreach my $field (qw( suggesteddate manageddate accepteddate )) { - my $from = $field . "_from"; - my $to = $field . "_to"; - my $from_dt = - $suggestion_ref->{$from} - ? eval { dt_from_string( $suggestion_ref->{$from} ) } - : undef; - my $to_dt = - $suggestion_ref->{$to} - ? eval { dt_from_string( $suggestion_ref->{$to} ) } - : undef; + my $from = delete $search_params->{"${field}_from"}; + my $to = delete $search_params->{"${field}_to"}; + + my $from_dt = $from && eval { dt_from_string($from) }; + my $to_dt = $to && eval { dt_from_string($to) }; if ( $from_dt || $to_dt ) { my $dtf = Koha::Database->new->schema->storage->datetime_parser; if ( $from_dt && $to_dt ) { - $search_params->{$field} = { -between => [ $from_dt, $to_dt ] }; + $search_params->{$field} = { -between => [ $dtf->format_date($from_dt), $dtf->format_date($to_dt) ] }; } elsif ( $from_dt ) { - $search_params->{$field} = { '>=' => $from_dt }; + $search_params->{$field} = { '>=' => $dtf->format_date($from_dt) }; } elsif ( $to_dt ) { - $search_params->{$field} = { '<=' => $to_dt }; + $search_params->{$field} = { '<=' => $dtf->format_date($to_dt) }; } } } -- 2.20.1