From a13ba009c77e7409abfc8cfd4f4f6ba999d0ea3c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sun, 24 Apr 2016 17:38:57 +0100 Subject: [PATCH] Bug 16276: Change to GetBorrowersToExpunge to take last_seen into account Content-Type: text/plain; charset=utf-8 Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: Nicolas Legrand With small change: number of tests in t/db_dependent/Members.t https://bugs.koha-community.org/show_bug.cgi?id=12276 Signed-off-by: Marcel de Rooy --- C4/Members.pm | 5 +++++ t/db_dependent/Members.t | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 061172f..54415d0 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1677,6 +1677,7 @@ sub GetBorrowersToExpunge { my $params = shift; my $filterdate = $params->{'not_borrowed_since'}; my $filterexpiry = $params->{'expired_before'}; + my $filterlastseen = $params->{'last_seen'}; my $filtercategory = $params->{'category_code'}; my $filterbranch = $params->{'branchcode'} || ((C4::Context->preference('IndependentBranches') @@ -1717,6 +1718,10 @@ sub GetBorrowersToExpunge { $query .= " AND dateexpiry < ? "; push( @query_params, $filterexpiry ); } + if ( $filterlastseen ) { + $query .= ' AND lastseen < ? '; + push @query_params, $filterlastseen; + } if ( $filtercategory ) { $query .= " AND categorycode = ? "; push( @query_params, $filtercategory ); diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index 006207b..6974965 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 79; +use Test::More tests => 81; use Test::MockModule; use Data::Dumper; use C4::Context; @@ -376,9 +376,17 @@ is( scalar(@$patstodel),2,'Borrowers without issues deleted by expiration_date a $patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } ); is( scalar(@$patstodel),2,'Borrowers without issues deleted by last issue date'); - - - +# Test GetBorrowersToExpunge and TrackLastPatronActivity +$dbh->do(q|UPDATE borrowers SET lastseen=NULL|); +$builder->build({ source => 'Borrower', value => { lastseen => '2016-01-01 01:01:01', guarantorid => undef } } ); +$builder->build({ source => 'Borrower', value => { lastseen => '2016-02-02 02:02:02', guarantorid => undef } } ); +$builder->build({ source => 'Borrower', value => { lastseen => '2016-03-03 03:03:03', guarantorid => undef } } ); +$patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' }); +is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' ); +$patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' }); +is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' ); +$patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' }); +is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' ); # Regression tests for BZ13502 ## Remove all entries with userid='' (should be only 1 max) -- 1.7.10.4