Bugzilla – Attachment 151720 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.73 KB, created by
Marcel de Rooy
on 2023-05-26 07:56:35 UTC
(
hide
)
Description:
Bug 33837: Add datetime comparison to filter_by_last_update
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-05-26 07:56:35 UTC
Size:
2.73 KB
patch
obsolete
>From 4c35487705bd48e500bc3a263e7206c9fd12a7d9 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 >Content-Type: text/plain; charset=utf-8 > >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> >--- > Koha/Objects.pm | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 133d0cb08e..6d1467c41d 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.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