Bug 16276: Change to GetBorrowersToExpunge to take last_seen into account
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sun, 24 Apr 2016 16:38:57 +0000 (17:38 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 13 Sep 2016 17:27:42 +0000 (17:27 +0000)
Sponsored-by: BULAC - http://www.bulac.fr/
Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>
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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/Members.pm
t/db_dependent/Members.t

index 6644c3a..4b2d7ff 100644 (file)
@@ -1477,6 +1477,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')
@@ -1517,6 +1518,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 );
index 006207b..6974965 100755 (executable)
@@ -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)