Bugzilla – Attachment 153919 Details for
Bug 33837
Objects->filter_by_last_update: Does not allow time comparison
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33837: Remove datetime parameter
Bug-33837-Remove-datetime-parameter.patch (text/plain), 6.41 KB, created by
Marcel de Rooy
on 2023-07-26 12:12:58 UTC
(
hide
)
Description:
Bug 33837: Remove datetime parameter
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-07-26 12:12:58 UTC
Size:
6.41 KB
patch
obsolete
>From 37fc0decca4ae62612d7361e477d6bc7de7208f2 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 21 Jul 2023 14:32:11 +0200 >Subject: [PATCH] Bug 33837: Remove datetime parameter >Content-Type: text/plain; charset=utf-8 > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >[EDIT] Perltidied one line in cleanup_database.pl. >--- > Koha/Objects.pm | 10 +++---- > misc/cronjobs/cleanup_database.pl | 6 +++++ > t/db_dependent/Koha/Objects.t | 43 ++++++++++++++++++++----------- > 3 files changed, 38 insertions(+), 21 deletions(-) > >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 70f5be29b3..dc3d044bd3 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -235,7 +235,6 @@ sub update { > my $filtered_objects = $objects->filter_by_last_update({ > from => $date1, to => $date2, > days|older_than => $days, min_days => $days, younger_than => $days, >- datetime => 1, > }); > > You should pass at least one of the parameters: from, to, days|older_than, >@@ -243,7 +242,6 @@ min_days or younger_than. Make sure that they do not conflict with each other > to get meaningful results. > Note: from, to and min_days are inclusive! And by nature days|older_than > and younger_than are exclusive. >-The optional parameter datetime allows datetime comparison. > > The from and to parameters can be DateTime objects or date strings. > >@@ -257,20 +255,20 @@ sub filter_by_last_update { > unless grep { exists $params->{$_} } qw/days from to older_than younger_than min_days/; > > my $dtf = Koha::Database->new->schema->storage->datetime_parser; >- my $method = $params->{datetime} ? 'format_datetime' : 'format_date'; > foreach my $p ( qw/days older_than younger_than min_days/ ) { > next if !exists $params->{$p}; > my $dt = Koha::DateUtils::dt_from_string(); > my $operator = { days => '<', older_than => '<', min_days => '<=' }->{$p} // '>'; >- $conditions->{$operator} = $dtf->$method( $dt->subtract( days => $params->{$p} ) ); >+ $dt->subtract( days => $params->{$p} )->truncate( to => 'day' ); >+ $conditions->{$operator} = $dtf->format_datetime( $dt ); > } > if ( exists $params->{from} ) { > my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from}); >- $conditions->{'>='} = $dtf->$method( $from ); >+ $conditions->{'>='} = $dtf->format_datetime( $from ); > } > if ( exists $params->{to} ) { > my $to = ref($params->{to}) ? $params->{to} : dt_from_string($params->{to}); >- $conditions->{'<='} = $dtf->$method( $to ); >+ $conditions->{'<='} = $dtf->format_datetime( $to ); > } > > return $self->search( >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index 60b3652012..6681a0b3bc 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -673,6 +673,12 @@ if ($pTransfers) { > > if (defined $pPseudoTransactions or $pPseudoTransactionsFrom or $pPseudoTransactionsTo ) { > print "Purging pseudonymized transactions\n" if $verbose; >+ if ($pPseudoTransactionsTo) { >+ $pPseudoTransactionsTo = dt_from_string($pPseudoTransactionsTo); >+ if ( $pPseudoTransactionsTo->hour == 0 && $pPseudoTransactionsTo->minute == 0 ) { >+ $pPseudoTransactionsTo->set( hour => 23, minute => 59, second => 59 ); >+ } >+ } > my $anonymized_transactions = Koha::PseudonymizedTransactions->filter_by_last_update( > { > timestamp_column_name => 'datetime', >diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t >index 09082df574..b7cda24f4e 100755 >--- a/t/db_dependent/Koha/Objects.t >+++ b/t/db_dependent/Koha/Objects.t >@@ -1188,22 +1188,35 @@ subtest "filter_by_last_update" => sub { > ); > }; > >- subtest 'Parameters datetime, older_than, younger_than' => sub { >+ subtest 'Parameters older_than, younger_than' => sub { > my $now = dt_from_string(); >- my $rs = Koha::Patrons->search({ borrowernumber => { -in => \@borrowernumbers } } ); >- $rs->update({ updated_on => $now->clone->subtract( hours => 25 ) }); >- is( $rs->filter_by_last_update({ timestamp_column_name => 'updated_on', from => $now })->count, 0, 'All updated yesterday' ); >- is( $rs->filter_by_last_update({ timestamp_column_name => 'updated_on', from => $now->clone->subtract( days => 1 ) })->count, >- 6, 'Yesterday, truncated from is inclusive' ); >- is( $rs->filter_by_last_update({ timestamp_column_name => 'updated_on', from => $now->clone->subtract( days => 1 ), >- datetime => 1 })->count, 0, 'Yesterday, not truncated, one hour too late' ); >- is( $rs->filter_by_last_update({ timestamp_column_name => 'updated_on', from => $now->clone->subtract( hours => 25 ), >- datetime => 1 })->count, 6, 'Yesterday - 1h, not truncated, within time frame' ); >- >- is( $rs->filter_by_last_update({ timestamp_column_name => 'updated_on', younger_than => 2, older_than => 1 })->count, >- 0, 'when using dates, we will find nothing' ); >- is( $rs->filter_by_last_update({ timestamp_column_name => 'updated_on', younger_than => 2, older_than => 1, datetime => 1 })->count, >- 6, 'when using datetime, we will find them all' ); >+ my $rs = Koha::Patrons->search( { borrowernumber => { -in => \@borrowernumbers } } ); >+ $rs->update( { updated_on => $now->clone->subtract( hours => 25 ) } ); >+ is( >+ $rs->filter_by_last_update( { timestamp_column_name => 'updated_on', from => $now } )->count, 0, >+ 'All updated yesterday' >+ ); >+ is( >+ $rs->filter_by_last_update( >+ { timestamp_column_name => 'updated_on', from => $now->clone->subtract( days => 1 )->truncate( to => 'day' ) } >+ )->count, >+ 6, >+ 'Yesterday, truncated from is inclusive' >+ ); >+ is( >+ $rs->filter_by_last_update( >+ { timestamp_column_name => 'updated_on', from => $now->clone->subtract( days => 1 ), } >+ )->count, >+ 0, >+ 'Yesterday, not truncated, one hour too late' >+ ); >+ is( >+ $rs->filter_by_last_update( >+ { timestamp_column_name => 'updated_on', from => $now->clone->subtract( hours => 25 ), } >+ )->count, >+ 6, >+ 'Yesterday - 1h, not truncated, within time frame' >+ ); > }; > > $schema->storage->txn_rollback; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33837
:
151720
|
151721
|
151722
|
151723
|
153778
|
153898
|
153900
|
153915
|
153916
|
153917
|
153918
|
153919
|
153920
|
153947
|
153948
|
153949
|
153950
|
153951