From f18118f18f8930d4765abecafe43776ef42877d4 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 15 Apr 2020 13:31:59 -0400 Subject: [PATCH] Bug 14708: Skip AnonymousPatron in GetBorrowersToExpunge Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- C4/Members.pm | 5 +++++ t/db_dependent/Members.t | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 6c10eeeb2c..854c5c5f10 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -437,6 +437,11 @@ sub GetBorrowersToExpunge { push @query_params,$filterdate; } + if ( my $anonymous_patron = C4::Context->preference("AnonymousPatron") ) { + $query .= q{ AND borrowernumber != ? }; + push( @query_params, $anonymous_patron ); + } + warn $query if $debug; my $sth = $dbh->prepare($query); diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index ff5fe994ff..cac634f252 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 47; +use Test::More tests => 48; use Test::MockModule; use Test::Exception; @@ -248,11 +248,19 @@ $builder->build({ # IndependentBranches is off. t::lib::Mocks::mock_preference('IndependentBranches', 0); +my $anonymous_patron = Koha::Patron->new({ categorycode => 'CIVILIAN', branchcode => $library2->{branchcode} })->store->borrowernumber; +t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_patron); + my $owner = Koha::Patron->new({ categorycode => 'STAFFER', branchcode => $library2->{branchcode} })->store->borrowernumber; my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } ); + +AddPatronsToList( { list => $list1, borrowernumbers => [$anonymous_patron] } ); +my $patstodel = GetBorrowersToExpunge( { patron_list_id => $list1->patron_list_id() } ); +is( scalar(@$patstodel), 0, 'Anonymous Patron not deleted from list' ); + my @listpatrons = ($bor1inlist, $bor2inlist); AddPatronsToList( { list => $list1, borrowernumbers => \@listpatrons }); -my $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } ); +$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } ); is( scalar(@$patstodel),0,'No staff deleted from list of all staff'); Koha::Patrons->find($bor2inlist)->set({ categorycode => 'CIVILIAN' })->store; $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} ); -- 2.39.5