Bugzilla – Attachment 179151 Details for
Bug 37418
Expand delete_patron.pl with option to not delete patrons with restrictions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions
Bug-37418-deletepatronspl-Exclude-patrons-with-res.patch (text/plain), 6.86 KB, created by
Raphael Straub
on 2025-03-11 09:50:53 UTC
(
hide
)
Description:
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions
Filename:
MIME Type:
Creator:
Raphael Straub
Created:
2025-03-11 09:50:53 UTC
Size:
6.86 KB
patch
obsolete
>From 1dc9322c8ff1321fa0d970b802e20f5d849d1f84 Mon Sep 17 00:00:00 2001 >From: Raphael Straub <raphael.straub@kit.edu> >Date: Tue, 11 Mar 2025 09:25:25 +0000 >Subject: [PATCH] Bug 37418: delete_patrons.pl: Exclude patrons with > restrictions > >Add the option "--without_restriction_type" so that delete_patrons.pl >does not delete patrons with given restriction types. > >To test: >1) Run > misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01 > and choose a borrowernumber that would be deleted. >2) In your browser go to > /cgi-bin/koha/members/moremember.pl?borrowernumber=<borrowernumber> > and add a manual restriction to this patron. >3) Apply the patch. >4) Run > misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01 \ > --without_restriction_type MANUAL >5) Check that the patron with the manual restriction would not be > deleted. > >Sponsored-by: Karlsruhe Institute of Technology (KIT) >Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl> >--- > C4/Members.pm | 16 ++++++++- > misc/cronjobs/delete_patrons.pl | 57 +++++++++++++++++++++++---------- > 2 files changed, 55 insertions(+), 18 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index 06365485b3..dab47be321 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -248,7 +248,8 @@ sub GetBorrowersToExpunge { > ? C4::Context->userenv->{branch} > : "" > ); >- my $filterpatronlist = $params->{'patron_list_id'}; >+ my $filterpatronlist = $params->{'patron_list_id'}; >+ my $without_restriction_types = $params->{'without_restriction_types'}; > > my $dbh = C4::Context->dbh; > my $query = q| >@@ -308,6 +309,19 @@ sub GetBorrowersToExpunge { > $query .= " AND ( latestissue < ? OR latestissue IS NULL ) "; > push @query_params, $filterdate; > } >+ if ( ref($without_restriction_types) ne 'ARRAY' ) { >+ $without_restriction_types = [$without_restriction_types]; >+ } >+ if ( @$without_restriction_types > 0 ) { >+ $query .= q| >+ AND NOT EXISTS ( >+ SELECT 1 >+ FROM borrower_debarments >+ WHERE borrower_debarments.borrowernumber = xxx.borrowernumber >+ AND borrower_debarments.type IN (| >+ . join( ',', ('?') x @$without_restriction_types ) . "))"; >+ push @query_params, @$without_restriction_types; >+ } > > if ( my $anonymous_patron = C4::Context->preference("AnonymousPatron") ) { > $query .= q{ AND borrowernumber != ? }; >diff --git a/misc/cronjobs/delete_patrons.pl b/misc/cronjobs/delete_patrons.pl >index ab18450f17..3820e26385 100755 >--- a/misc/cronjobs/delete_patrons.pl >+++ b/misc/cronjobs/delete_patrons.pl >@@ -12,23 +12,24 @@ use Koha::Patrons; > use C4::Log qw( cronlogaction ); > > my ( >- $help, $verbose, $not_borrowed_since, $expired_before, $last_seen, >- @category_code, $branchcode, $file, $confirm >+ $help, $verbose, $not_borrowed_since, $expired_before, $last_seen, >+ @category_code, $branchcode, $file, @without_restriction_types, $confirm > ); > > my $command_line_options = join( " ", @ARGV ); > cronlogaction( { info => $command_line_options } ); > > 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, >- 'library:s' => \$branchcode, >- 'file:s' => \$file, >- 'c|confirm' => \$confirm, >+ '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, >+ 'library:s' => \$branchcode, >+ 'file:s' => \$file, >+ 'without_restriction_type:s' => \@without_restriction_types, >+ 'c|confirm' => \$confirm, > ) || pod2usage(1); > > if ($help) { >@@ -49,6 +50,21 @@ unless ( $not_borrowed_since or $expired_before or $last_seen or @category_code > pod2usage(q{At least one filter is mandatory}); > } > >+if ( @without_restriction_types > 0 ) { >+ my %restriction_types; >+ @restriction_types{ map { $_->code() } Koha::Patron::Restriction::Types->search()->as_list } = (); >+ >+ my @invalid_restriction_types; >+ foreach my $restriction_type (@without_restriction_types) { >+ if ( !exists $restriction_types{$restriction_type} ) { >+ push @invalid_restriction_types, $restriction_type; >+ } >+ } >+ if ( @invalid_restriction_types > 0 ) { >+ die 'Invalid restriction type(s): ' . join ', ', @invalid_restriction_types; >+ } >+} >+ > my @file_members; > if ($file) { > open( my $fh, '<:encoding(UTF-8)', $file ) or die "Could not open file $file' $!"; >@@ -65,11 +81,12 @@ my $members; > 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, >- branchcode => $branchcode, >+ not_borrowed_since => $not_borrowed_since, >+ expired_before => $expired_before, >+ last_seen => $last_seen, >+ category_code => \@category_code, >+ branchcode => $branchcode, >+ without_restriction_types => \@without_restriction_types > } > ); > } >@@ -149,7 +166,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] [--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] [--without_restriction_type=TYPE] [--without_restriction_type=TYPE ...] > > Dates should be in ISO format, e.g., 2013-07-19, and can be generated > with `date -d '-3 month' --iso-8601`. >@@ -202,6 +219,12 @@ Delete patrons in this library. > Delete patrons whose borrower numbers are in this file. If other criteria are defined > it will only delete those in the file that match those criteria. > >+=item B<--without_restriction_type> >+ >+Delete patrons who DO NOT have a debarment with this restriction type. >+ >+Can be used multiple times for additional restriction types. >+ > =item B<-c|--confirm> > > This flag must be provided in order for the script to actually >-- >2.39.5
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 37418
:
169688
|
169879
|
176777
|
179151
|
180715
|
180716