Bugzilla – Attachment 116012 Details for
Bug 27050
Allow multiple category_codes in delete_patrons.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27050 - Allow multiple category_codes in delete_patrons.pl
Bug-27050---Allow-multiple-categorycodes-in-delete.patch (text/plain), 7.14 KB, created by
Marcel de Rooy
on 2021-01-29 09:41:44 UTC
(
hide
)
Description:
Bug 27050 - Allow multiple category_codes in delete_patrons.pl
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2021-01-29 09:41:44 UTC
Size:
7.14 KB
patch
obsolete
>From 6f352119de81918757eab88add211e785a9317cb Mon Sep 17 00:00:00 2001 >From: Timothy Alexis Vass <timothy_alexis.vass@ub.lu.se> >Date: Fri, 27 Nov 2020 13:21:11 +0000 >Subject: [PATCH] Bug 27050 - Allow multiple category_codes in > delete_patrons.pl >Content-Type: text/plain; charset=utf-8 > >This patch allows multiple --category_code <categorycode> in delete_patrons.pl > >The t/db_dependent/Members.t test has 2 added testcases with multiple category_code. > >To test: >1) Run the test: prove -l . -v t/db_dependent/Members.t >2) This requires records in the database with at least two category codes. For example PT and ST. >3) Run the script: delete_patrons.pl --category_code PT >4) Confirm the number of patrons that would have been deleted. >5) Run the script: delete_patrons.pl --category_code PT --category-code ST >6) Confirm the number of patrons that would have been deleted. >7) Sign Off > >Sponsored-by: Lunds Universitetsbibliotek > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > C4/Members.pm | 9 ++++++--- > misc/cronjobs/delete_patrons.pl | 15 +++++++++------ > t/db_dependent/Members.t | 6 +++++- > 3 files changed, 20 insertions(+), 10 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index a6760b8174..05056345e3 100644 >--- a/C4/Members.pm >+++ b/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 = ? "; >diff --git a/misc/cronjobs/delete_patrons.pl b/misc/cronjobs/delete_patrons.pl >index f9ad0eca88..1f6bcc9a25 100755 >--- a/misc/cronjobs/delete_patrons.pl >+++ b/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. >diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t >index cac634f252..880c21c3bf 100755 >--- a/t/db_dependent/Members.t >+++ b/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() } ); >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27050
:
114042
|
114094
|
116012
|
116503