From c588db5095240385dfbd52aec455c22637a74240 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 Sponsored-by: BULAC - http://www.bulac.fr/ --- 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 ed82f86..5ec18da 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1754,6 +1754,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') @@ -1794,6 +1795,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 e369128..d470770 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 76; +use Test::More tests => 79; use Test::MockModule; use Data::Dumper; use C4::Context; @@ -353,9 +353,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) -- 2.7.0