Bugzilla – Attachment 153778 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.84 KB, created by
Jonathan Druart
on 2023-07-21 12:32:33 UTC
(
hide
)
Description:
Bug 33837: Remove datetime parameter
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-07-21 12:32:33 UTC
Size:
6.84 KB
patch
obsolete
>From 4fbfd8b480dddc6409e3838f7814047b08689cbd 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 > >--- > Koha/Notice/Util.pm | 2 +- > Koha/Objects.pm | 9 +++---- > misc/cronjobs/cleanup_database.pl | 6 +++++ > t/db_dependent/Koha/Objects.t | 43 ++++++++++++++++++++----------- > 4 files changed, 38 insertions(+), 22 deletions(-) > >diff --git a/Koha/Notice/Util.pm b/Koha/Notice/Util.pm >index 4e515d4b5db..903550b893e 100644 >--- a/Koha/Notice/Util.pm >+++ b/Koha/Notice/Util.pm >@@ -122,7 +122,7 @@ sub _get_domain_count { > message_transport_type => 'email', > status => 'sent', > to_address => { 'LIKE', '%'.$domain }, >- })->filter_by_last_update({ timestamp_column_name => 'updated_on', from => $start_dt, datetime => 1 })->count; >+ })->filter_by_last_update({ timestamp_column_name => 'updated_on', from => $start_dt, })->count; > } > $limits->{$group}->{count} = $sum; > } >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 70f5be29b3d..effe03ef361 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,19 @@ 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} ) ); >+ $conditions->{$operator} = $dtf->format_datetime( $dt->subtract( days => $params->{$p} ) ); > } > 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 60b36520121..129bfa76331 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 09082df574d..6b486cbe07f 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 ) } >+ )->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.25.1
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