@@ -, +, @@ delete_patrons.pl --- C4/Members.pm | 9 ++++++--- misc/cronjobs/delete_patrons.pl | 15 +++++++++------ t/db_dependent/Members.t | 6 +++++- 3 files changed, 20 insertions(+), 10 deletions(-) --- a/C4/Members.pm +++ a/C4/Members.pm @@ -362,7 +362,7 @@ sub get_cardnumber_length { $borrowers = &GetBorrowersToExpunge( not_borrowed_since => $not_borrowed_since, expired_before => $expired_before, - category_code => $category_code, + category_code => \@category_code, patron_list_id => $patron_list_id, branchcode => $branchcode ); @@ -424,8 +424,11 @@ sub GetBorrowersToExpunge { push @query_params, $filterlastseen; } if ( $filtercategory ) { - $query .= " AND categorycode = ? "; - push( @query_params, $filtercategory ); + if (ref($filtercategory) ne 'ARRAY' ) { + $filtercategory = [ $filtercategory ]; + } + $query .= " AND categorycode IN (" . join(',', ('?') x @$filtercategory) . ") "; + push( @query_params, @$filtercategory ); } if ( $filterpatronlist ){ $query.=" AND patron_list_id = ? "; --- a/misc/cronjobs/delete_patrons.pl +++ a/misc/cronjobs/delete_patrons.pl @@ -12,14 +12,15 @@ use Koha::Patrons; use C4::Log; my ( $help, $verbose, $not_borrowed_since, $expired_before, $last_seen, - $category_code, $branchcode, $file, $confirm ); + @category_code, $branchcode, $file, $confirm ); + GetOptions( 'h|help' => \$help, 'v|verbose' => \$verbose, 'not_borrowed_since:s' => \$not_borrowed_since, 'expired_before:s' => \$expired_before, 'last_seen:s' => \$last_seen, - 'category_code:s' => \$category_code, + 'category_code:s' => \@category_code, 'library:s' => \$branchcode, 'file:s' => \$file, 'c|confirm' => \$confirm, @@ -39,7 +40,7 @@ if ( $last_seen and not C4::Context->preference('TrackLastPatronActivity') ) { pod2usage(q{The --last_seen option cannot be used with TrackLastPatronActivity turned off}); } -unless ( $not_borrowed_since or $expired_before or $last_seen or $category_code or $branchcode or $file ) { +unless ( $not_borrowed_since or $expired_before or $last_seen or @category_code or $branchcode or $file ) { pod2usage(q{At least one filter is mandatory}); } @@ -58,13 +59,13 @@ if ($file) { } my $members; -if ( $not_borrowed_since or $expired_before or $last_seen or $category_code or $branchcode ) { +if ( $not_borrowed_since or $expired_before or $last_seen or @category_code or $branchcode ) { $members = GetBorrowersToExpunge( { not_borrowed_since => $not_borrowed_since, expired_before => $expired_before, last_seen => $last_seen, - category_code => $category_code, + category_code => \@category_code, branchcode => $branchcode, } ); @@ -143,7 +144,7 @@ delete_patrons - This script deletes patrons =head1 SYNOPSIS -delete_patrons.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--not_borrowed_since=DATE] [--expired_before=DATE] [--last-seen=DATE] [--category_code=CAT] [--library=LIBRARY] [--file=FILE] +delete_patrons.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--not_borrowed_since=DATE] [--expired_before=DATE] [--last-seen=DATE] [--category_code=CAT] [--category_code=CAT ...] [--library=LIBRARY] [--file=FILE] Dates should be in ISO format, e.g., 2013-07-19, and can be generated with `date -d '-3 month' --iso-8601`. @@ -178,6 +179,8 @@ The system preference TrackLastPatronActivity must be enabled to use this option Delete patrons who have this category code. +Can be used multiple times for additional category codes. + =item B<--library> Delete patrons in this library. --- a/t/db_dependent/Members.t +++ a/t/db_dependent/Members.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 48; +use Test::More tests => 50; use Test::MockModule; use Test::Exception; @@ -300,6 +300,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 => ['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() } ); is( scalar(@$patstodel),1,'Borrower with issue not deleted by expiration_date and list'); $builder->schema->resultset( 'Issue' )->delete_all; @@ -307,6 +309,8 @@ $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} ok( scalar(@$patstodel)== 2,'Borrowers without issue deleted from list'); $patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } ); is( scalar(@$patstodel),2,'Borrowers without issues deleted by category_code and list'); +$patstodel = GetBorrowersToExpunge( {category_code => ['CIVILIAN','STAFFER'],patron_list_id => $list1->patron_list_id() } ); +is( scalar(@$patstodel),2,'Borrowers without issues deleted by multiple category_code and list'); $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } ); is( scalar(@$patstodel),2,'Borrowers without issues deleted by expiration_date and list'); $patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } ); --