Bugzilla – Attachment 158318 Details for
Bug 15157
Cronjob to automatically restrict patrons with pending/unpaid charges
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15157: (QA follow-up) Some more changes
Bug-15157-QA-follow-up-Some-more-changes.patch (text/plain), 3.38 KB, created by
Marcel de Rooy
on 2023-11-03 10:06:10 UTC
(
hide
)
Description:
Bug 15157: (QA follow-up) Some more changes
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-11-03 10:06:10 UTC
Size:
3.38 KB
patch
obsolete
>From 8bfd8efbebb2ccff5373e36265cfcd490bce2722 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Fri, 3 Nov 2023 09:33:39 +0000 >Subject: [PATCH] Bug 15157: (QA follow-up) Some more changes >Content-Type: text/plain; charset=utf-8 > >Renamed some vars. Removed unused $success. >Extended die statement. >Added Modern::Perl. > >Added verbose parameter. >Added some logic around the confirm parameter. Making it possible >to run the script in 'dry' mode. >Print totals at the end. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > misc/cronjobs/debar_patrons_with_fines.pl | 39 ++++++++++++++++------- > 1 file changed, 27 insertions(+), 12 deletions(-) > >diff --git a/misc/cronjobs/debar_patrons_with_fines.pl b/misc/cronjobs/debar_patrons_with_fines.pl >index d810226a02..cb166121e8 100755 >--- a/misc/cronjobs/debar_patrons_with_fines.pl >+++ b/misc/cronjobs/debar_patrons_with_fines.pl >@@ -66,8 +66,7 @@ Confirm that the script should actually undertake the debarments > > =cut > >-use strict; >-use warnings; >+use Modern::Perl; > use Getopt::Long qw( GetOptions ); > use Pod::Usage qw( pod2usage ); > >@@ -77,7 +76,7 @@ use Koha::Patron::Debarments; > > use C4::Log qw( cronlogaction ); > >-my ( $amount, $help, $confirm, $message, $expiration, $file ); >+my ( $amount, $help, $confirm, $message, $expiration, $file, $verbose ); > GetOptions( > 'a|amount:i' => \$amount, > 'h|help' => \$help, >@@ -85,35 +84,51 @@ GetOptions( > 'm|message:s' => \$message, > 'f|file:s' => \$file, > 'e|expiration:s' => \$expiration, >+ 'v|verbose' => \$verbose, > ) || pod2usage(2); > pod2usage(1) if $help; >-pod2usage(1) unless ( $confirm && ( $message || $file ) ); >+pod2usage(1) unless $message || $file; > > cronlogaction(); >-my $badBorrowers = Koha::Patrons->filter_by_amount_owed( { more_than => $amount // 0 } ); >+my $patrons = Koha::Patrons->filter_by_amount_owed( { more_than => $amount // 0 } ); > $message = getMessageContent(); > >-while ( my $bb = $badBorrowers->next ) { >+my $count_patrons = 0; >+my $errors = 0; >+while ( my $patron = $patrons->next ) { >+ print "Found patron " . $patron->id . "\n" if $verbose; >+ if ( !$confirm ) { >+ $count_patrons++; >+ next; >+ } > >- #Don't crash, but keep debarring as long as you can! >+ # Don't crash, but keep debarring as long as you can! > eval { >- my $success = Koha::Patron::Debarments::AddDebarment( >+ Koha::Patron::Debarments::AddDebarment( > { >- borrowernumber => $bb->borrowernumber, >+ borrowernumber => $patron->id, > expiration => $expiration, > type => 'MANUAL', > comment => $message, > } > ); > }; >- if ($@) { >- print $@. "\n"; >+ if ( my $error = $@ ) { >+ warn 'debarment failed for patron ' . $patron->id . ": $error"; >+ $errors++; >+ next; > } >+ $count_patrons++; > } > >+# Print totals >+my $verb = $confirm ? 'Debarred' : 'Found'; >+print "debar_patrons_with_fines: $verb $count_patrons patrons"; >+print( $errors ? ", had $errors failures\n" : "\n" ); >+ > sub getMessageContent { > return $message if ($message); >- open( my $FH, "<:encoding(UTF-8)", $file ) or die "$!\n"; >+ open( my $FH, "<:encoding(UTF-8)", $file ) or die "Could not open $file: $!\n"; > my @msg = <$FH>; > close $FH; > return join( "", @msg ); >-- >2.30.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 15157
:
44643
|
44645
|
44646
|
109220
|
124894
|
124895
|
124896
|
129701
|
129702
|
129703
|
129704
|
130103
|
158288
|
158289
|
158290
|
158291
|
158292
|
158315
|
158316
|
158317
| 158318