From 96adb7373ab3b39a42dc3a8304f050ee81c991c4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 30 Jul 2021 07:20:20 +0200 Subject: [PATCH] Bug 28585: Revert of the 3 commits Revert "Bug 28585: (follow-up) Tests for q= supporting date/date-time parameters" This reverts commit 89d9dd6d5d3c76f0fd7e9062cb29ac93357b9088. Revert "Bug 28585: Use the datetime_parser for handling API dates" This reverts commit 2e266f35f9cae5f4b90d5e28e72990e6ba1bfeca. Revert "Bug 28585: Regression tests" This reverts commit 8d74d3226ad9e596f7aec77ce61ac378db7a5e4a. Signed-off-by: Jonathan Druart --- Koha/Object.pm | 8 +---- t/db_dependent/api/v1/patrons.t | 55 +-------------------------------- 2 files changed, 2 insertions(+), 61 deletions(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index 6e7b84b282..08602da67f 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -694,7 +694,6 @@ sub attributes_from_api { my $params; my $columns_info = $self->_result->result_source->columns_info; - my $dtf = $self->_result->result_source->storage->datetime_parser; while (my ($key, $value) = each %{ $from_api_params } ) { my $koha_field_name = @@ -709,12 +708,7 @@ sub attributes_from_api { } elsif ( _date_or_datetime_column_type( $columns_info->{$koha_field_name}->{data_type} ) ) { try { - if ( $columns_info->{$koha_field_name}->{data_type} eq 'date' ) { - $value = $dtf->format_date(dt_from_string($value, 'rfc3339')); - } - else { - $value = $dtf->format_datetime(dt_from_string($value, 'rfc3339')); - } + $value = dt_from_string($value, 'rfc3339'); } catch { Koha::Exceptions::BadParameter->throw( parameter => $key ); diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 5b1e33119b..dbe6c1bbc5 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -28,14 +28,11 @@ use t::lib::Dates; use C4::Auth; use Koha::Database; -use Koha::DateUtils qw(dt_from_string output_pref); use Koha::Exceptions::Patron; use Koha::Exceptions::Patron::Attribute; use Koha::Patron::Attributes; use Koha::Patron::Debarments qw/AddDebarment/; -use JSON qw(encode_json); - my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; @@ -50,7 +47,7 @@ subtest 'list() tests' => sub { $schema->storage->txn_rollback; subtest 'librarian access tests' => sub { - plan tests => 17; + plan tests => 16; $schema->storage->txn_begin; @@ -88,56 +85,6 @@ subtest 'list() tests' => sub { ->json_is( '/0/restricted' => Mojo::JSON->true ) ->json_hasnt('/1'); - subtest 'searching date and date-time fields' => sub { - - plan tests => 12; - - my $date_of_birth = '1980-06-18'; - my $last_seen = '2021-06-25 14:05:35'; - - my $patron = $builder->build_object( - { - class => 'Koha::Patrons', - value => { - dateofbirth => $date_of_birth, - lastseen => $last_seen, - } - } - ); - - my $last_seen_rfc3339 = $last_seen . "z"; - - $t->get_ok("//$userid:$password@/api/v1/patrons?date_of_birth=" . $date_of_birth . "&cardnumber=" . $patron->cardnumber) - ->status_is(200) - ->json_is( '/0/patron_id' => $patron->id, 'Filtering by date works' ); - - $t->get_ok("//$userid:$password@/api/v1/patrons?last_seen=" . $last_seen_rfc3339 . "&cardnumber=" . $patron->cardnumber) - ->status_is(200) - ->json_is( '/0/patron_id' => $patron->id, 'Filtering by date-time works' ); - - my $q = encode_json( - { - date_of_birth => $date_of_birth, - cardnumber => $patron->cardnumber, - } - ); - - $t->get_ok("//$userid:$password@/api/v1/patrons?q=$q") - ->status_is(200) - ->json_is( '/0/patron_id' => $patron->id, 'Filtering by date works' ); - - $q = encode_json( - { - last_seen => $last_seen_rfc3339, - cardnumber => $patron->cardnumber, - } - ); - - $t->get_ok("//$userid:$password@/api/v1/patrons?q=$q") - ->status_is(200) - ->json_is( '/0/patron_id' => $patron->id, 'Filtering by date-time works' ); - }; - $schema->storage->txn_rollback; }; }; -- 2.39.5