Bugzilla – Attachment 119525 Details for
Bug 21549
Lock expired patron accounts after x days
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21549: Use filter_by_last_update from filter_by_dateexpiry
Bug-21549-Use-filterbylastupdate-from-filterbydate.patch (text/plain), 4.35 KB, created by
Marcel de Rooy
on 2021-04-13 11:12:42 UTC
(
hide
)
Description:
Bug 21549: Use filter_by_last_update from filter_by_dateexpiry
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2021-04-13 11:12:42 UTC
Size:
4.35 KB
patch
obsolete
>From 8b9c68e772e9c30f75aea8eda05330708823e31c Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 12 Apr 2021 16:12:03 +0200 >Subject: [PATCH] Bug 21549: Use filter_by_last_update from > filter_by_dateexpiry >Content-Type: text/plain; charset=utf-8 > >To not reengineer the patch this patch does not remove the new >subroutine but make it use the logic from >Koha::Objects->filter_by_last_update > >It also adds a new parameter "days_inclusive" > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Objects.pm | 7 +++++-- > Koha/Patrons.pm | 14 ++++++++------ > t/db_dependent/Koha/Objects.t | 12 ++++++++++++ > 3 files changed, 25 insertions(+), 8 deletions(-) > >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 2f16b35888..ed9366c010 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -257,7 +257,7 @@ sub update { > > my $filtered_objects = $objects->filter_by_last_update > >-days exclusive >+days exclusive by default (will be inclusive if days_inclusive is passed and set) > from inclusive > to inclusive > >@@ -266,6 +266,7 @@ to inclusive > sub filter_by_last_update { > my ( $self, $params ) = @_; > my $timestamp_column_name = $params->{timestamp_column_name} || 'timestamp'; >+ my $days_inclusive = $params->{days_inclusive} || 0; > my $conditions; > Koha::Exceptions::MissingParameter->throw( > "Missing mandatory parameter: days or from or to") >@@ -275,7 +276,9 @@ sub filter_by_last_update { > > my $dtf = Koha::Database->new->schema->storage->datetime_parser; > if ( exists $params->{days} ) { >- $conditions->{'<'} = $dtf->format_date( dt_from_string->subtract( days => $params->{days} ) ); >+ my $dt = Koha::DateUtils::dt_from_string(); >+ my $operator = $days_inclusive ? '<=' : '<'; >+ $conditions->{$operator} = $dtf->format_date( $dt->subtract( days => $params->{days} ) ); > } > if ( exists $params->{from} ) { > my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from}); >diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm >index 97fac5e60d..d42f035e4c 100644 >--- a/Koha/Patrons.pm >+++ b/Koha/Patrons.pm >@@ -243,12 +243,14 @@ sub delete { > > sub filter_by_dateexpiry { > my ( $class, $params ) = @_; >- my $days = $params->{days} || 0; >- my $parser = Koha::Database->new->schema->storage->datetime_parser; >- my $dt = dt_from_string()->subtract( days => $days ); >- return $class->search({ >- dateexpiry => { '<=' => $parser->format_datetime($dt) }, >- }); >+ >+ return $class->filter_by_last_update( >+ { >+ timestamp_column_name => 'dateexpiry', >+ days => $params->{days} || 0, >+ days_inclusive => 1, >+ } >+ ); > } > > =head3 search_unsubscribed >diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t >index afb00ee142..8e046e9afc 100755 >--- a/t/db_dependent/Koha/Objects.t >+++ b/t/db_dependent/Koha/Objects.t >@@ -1102,14 +1102,26 @@ subtest "filter_by_last_update" => sub { > is( $count, 3, '3 patrons have been updated before the last 2 days (exclusive)' ); > > $count = $patrons->filter_by_last_update( >+ { timestamp_column_name => 'updated_on', days => 2, days_inclusive => 1 } )->count; >+ is( $count, 4, '4 patrons have been updated before the last 2 days (inclusive)' ); >+ >+ $count = $patrons->filter_by_last_update( > { timestamp_column_name => 'updated_on', days => 1 } )->count; > is( $count, 4, '4 patrons have been updated before yesterday (exclusive)' ); > > $count = $patrons->filter_by_last_update( >+ { timestamp_column_name => 'updated_on', days => 1, days_inclusive => 1 } )->count; >+ is( $count, 5, '5 patrons have been updated before yesterday (inclusive)' ); >+ >+ $count = $patrons->filter_by_last_update( > { timestamp_column_name => 'updated_on', days => 0 } )->count; > is( $count, 5, '5 patrons have been updated before today (exclusive)' ); > > $count = $patrons->filter_by_last_update( >+ { timestamp_column_name => 'updated_on', days => 0, days_inclusive => 1 } )->count; >+ is( $count, 6, '6 patrons have been updated before today (inclusive)' ); >+ >+ $count = $patrons->filter_by_last_update( > { timestamp_column_name => 'updated_on', from => $now } )->count; > is( $count, 1, '1 patron has been updated "from today" (inclusive)' ); > >-- >2.11.0
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 21549
:
108000
|
108001
|
111480
|
111481
|
113914
|
113915
|
118493
|
118494
|
118495
|
118496
|
118517
|
118518
|
118519
|
118520
|
118521
|
119457
|
119458
|
119459
|
119460
|
119461
|
119462
|
119463
|
119464
| 119525 |
119526
|
119527