Bugzilla – Attachment 169688 Details for
Bug 37418
Expand delete_patron.pl / Patrons with defined restrictions should not be deleted
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.57 KB, created by
Raphael Straub
on 2024-07-26 10:28:09 UTC
(
hide
)
Description:
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions
Filename:
MIME Type:
Creator:
Raphael Straub
Created:
2024-07-26 10:28:09 UTC
Size:
6.57 KB
patch
obsolete
>From 0286ce5ec6068c9a112d35a59f7d7a227b1e0bd2 Mon Sep 17 00:00:00 2001 >From: Raphael Straub <raphael.straub@kit.edu> >Date: Wed, 24 Jul 2024 13:48:05 +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) >--- > C4/Members.pm | 14 +++++++++ > misc/cronjobs/delete_patrons.pl | 55 +++++++++++++++++++++++---------- > 2 files changed, 53 insertions(+), 16 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index 1d93b49fa1..9ffd4c0120 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -251,6 +251,7 @@ sub GetBorrowersToExpunge { > ? C4::Context->userenv->{branch} > : ""); > my $filterpatronlist = $params->{'patron_list_id'}; >+ my $without_restriction_types = $params->{'without_restriction_types'}; > > my $dbh = C4::Context->dbh; > my $query = q| >@@ -310,6 +311,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 7962233efa..ded05ad33a 100755 >--- a/misc/cronjobs/delete_patrons.pl >+++ b/misc/cronjobs/delete_patrons.pl >@@ -12,20 +12,21 @@ use Koha::Patrons; > use C4::Log qw( cronlogaction ); > > my ( $help, $verbose, $not_borrowed_since, $expired_before, $last_seen, >- @category_code, $branchcode, $file, $confirm ); >+ @category_code, $branchcode, $file, @without_restriction_types, $confirm ); > > my $command_line_options = join(" ",@ARGV); > > 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) { >@@ -46,6 +47,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; >+ } >+} >+ > cronlogaction({ info => $command_line_options }); > > my @file_members; >@@ -64,11 +80,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.2
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