From 1dfa520da5a6fba2e1b1cd3d24539a2d2fd524ea Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 9 Apr 2021 11:00:37 +0200 Subject: [PATCH] Bug 28001: (bug 27050 follow-up) Fix delete_patrons if no category passed GetBorrowersToExpunge must not crash if called with an empty patron category list Test plan: Call delete_patrons.pl with and without patron categories. The script must work as expected Signed-off-by: Owen Leonard Signed-off-by: Jonathan Druart --- C4/Members.pm | 6 ++++-- t/db_dependent/Members.t | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index f98ddecd43..c52f18add8 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -428,8 +428,10 @@ sub GetBorrowersToExpunge { if (ref($filtercategory) ne 'ARRAY' ) { $filtercategory = [ $filtercategory ]; } - $query .= " AND categorycode IN (" . join(',', ('?') x @$filtercategory) . ") "; - push( @query_params, @$filtercategory ); + if ( @$filtercategory ) { + $query .= " AND categorycode IN (" . join(',', ('?') x @$filtercategory) . ") "; + push( @query_params, @$filtercategory ); + } } if ( $filterpatronlist ){ $query.=" AND patron_list_id = ? "; diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index b7a1ceea15..367d0d2aff 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 53; +use Test::More tests => 54; use Test::MockModule; use Test::Exception; @@ -303,6 +303,8 @@ $patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patro is( scalar(@$patstodel),1,'Borrower with issue not deleted by branchcode and list'); $patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } ); is( scalar(@$patstodel),1,'Borrower with issue not deleted by category_code and list'); +$patstodel = GetBorrowersToExpunge( {category_code => [], patron_list_id => $list1->patron_list_id() } ); +is( scalar(@$patstodel),1,'category_code can contain an empty arrayref'); $patstodel = GetBorrowersToExpunge( {category_code => ['CIVILIAN','STAFFER'],patron_list_id => $list1->patron_list_id() } ); is( scalar(@$patstodel),1,'Borrower with issue not deleted by multiple category_code and list'); $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } ); -- 2.39.5