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 <oleonard@myacpl.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2021-04-09 11:00:37 +02:00
parent 21ea89d774
commit 1dfa520da5
2 changed files with 7 additions and 3 deletions

View File

@ -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 = ? ";

View File

@ -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() } );