Bugzilla – Attachment 153947 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: Add datetime comparison to filter_by_last_update
Bug-33837-Add-datetime-comparison-to-filterbylastu.patch (text/plain), 2.76 KB, created by
Jonathan Druart
on 2023-07-27 09:10:39 UTC
(
hide
)
Description:
Bug 33837: Add datetime comparison to filter_by_last_update
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-07-27 09:10:39 UTC
Size:
2.76 KB
patch
obsolete
>From 402537e7c8248c9ecdd30660ee3bb0a75bbef3e0 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 15 May 2023 09:48:58 +0000 >Subject: [PATCH] Bug 33837: Add datetime comparison to filter_by_last_update > >Test plan: >Verify that filter_by_last_update still works as expected by >running cleanup_database.pl with --messages DAYS parameter. >Look at the oldest messages.message_date (or insert one). >Run with -days X where today - X is before that date. >Run with -days Y where today - Y is just after it. > >Note: misc/cronjobs/cleanup_database.pl -confirm -messages -1 -v >will remove all messages including one you inserted just now. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > Koha/Objects.pm | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 133d0cb08e9..6d1467c41d8 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -232,11 +232,14 @@ sub update { > > =head3 filter_by_last_update > >-my $filtered_objects = $objects->filter_by_last_update >+my $filtered_objects = $objects->filter_by_last_update({ >+ days => $x, from => $date1, to => $date2, days_inclusive => 1, datetime => 1, >+}); > >-days exclusive by default (will be inclusive if days_inclusive is passed and set) >-from inclusive >-to inclusive >+Note: days are exclusive by default (will be inclusive if days_inclusive is passed and set). >+The parameters from and to are inclusive. They can be DateTime objects or date strings. >+You should pass at least one of the parameters days, from or to. >+The optional parameter datetime allows datetime comparison. > > =cut > >@@ -252,18 +255,19 @@ sub filter_by_last_update { > or exists $params->{to}; > > my $dtf = Koha::Database->new->schema->storage->datetime_parser; >+ my $method = $params->{datetime} ? 'format_datetime' : 'format_date'; > if ( exists $params->{days} ) { > my $dt = Koha::DateUtils::dt_from_string(); > my $operator = $days_inclusive ? '<=' : '<'; >- $conditions->{$operator} = $dtf->format_date( $dt->subtract( days => $params->{days} ) ); >+ $conditions->{$operator} = $dtf->$method( $dt->subtract( days => $params->{days} ) ); > } > if ( exists $params->{from} ) { > my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from}); >- $conditions->{'>='} = $dtf->format_date( $from ); >+ $conditions->{'>='} = $dtf->$method( $from ); > } > if ( exists $params->{to} ) { > my $to = ref($params->{to}) ? $params->{to} : dt_from_string($params->{to}); >- $conditions->{'<='} = $dtf->format_date( $to ); >+ $conditions->{'<='} = $dtf->$method( $to ); > } > > return $self->search( >-- >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