Bugzilla – Attachment 158290 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: Modernise and Update for bug 15156
Bug-15157-Modernise-and-Update-for-bug-15156.patch (text/plain), 6.73 KB, created by
Lucas Gass
on 2023-11-02 21:28:08 UTC
(
hide
)
Description:
Bug 15157: Modernise and Update for bug 15156
Filename:
MIME Type:
Creator:
Lucas Gass
Created:
2023-11-02 21:28:08 UTC
Size:
6.73 KB
patch
obsolete
>From ab6aec19e7787818c9b32e8060d2537839416084 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 15 Sep 2021 15:27:45 +0100 >Subject: [PATCH] Bug 15157: Modernise and Update for bug 15156 > >This patch updates the script to use filter_by_amount_owed, renames >it to debar_patrons_with_fines.pl and moves it to the cronjobs >directory whilst also adding a copyright notice and POD. > >We could add a series of options to the script to allow more fine >grained control. > >Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> >--- > misc/cronjobs/debar_patrons_with_fines.pl | 118 ++++++++++++++++++++++ > misc/debarrBorrowersWithFines.pl | 91 ----------------- > 2 files changed, 118 insertions(+), 91 deletions(-) > create mode 100755 misc/cronjobs/debar_patrons_with_fines.pl > delete mode 100644 misc/debarrBorrowersWithFines.pl > >diff --git a/misc/cronjobs/debar_patrons_with_fines.pl b/misc/cronjobs/debar_patrons_with_fines.pl >new file mode 100755 >index 00000000000..019d259cdfc >--- /dev/null >+++ b/misc/cronjobs/debar_patrons_with_fines.pl >@@ -0,0 +1,118 @@ >+#!/usr/bin/perl >+ >+# Copyright 2022 PTFS Europe >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+debar_patrons_with_fines.pl - Creates a debarment for all Patrons who have outstanding fines. >+ >+=head1 SYNOPSIS >+ >+ debar_patrons_with_fines.pl --help >+ debar_patrons_with_fines.pl -m "Message for user" >+ debar_patrons_with_fines.pl -f "/var/lib/koha/site/debar_message.txt" >+ debar_patrons_with_fines.pl -m "Message for user" -e '2022-12-31' >+ >+=head1 DESCRIPTION >+ >+This script can be used to automatically debar patrons who have an outstanding >+debt to the library. >+ >+=head1 OPTIONS >+ >+=over 8 >+ >+=item B<-h|--help> >+ >+Display the help message and exit >+ >+=item B<-m|--message> >+ >+Add the passed message in the debarment comment >+ >+=item B<-f|--messagefile> >+ >+Add the content of the passed file in the debarment comment >+ >+=item B<-e|--expiration> >+ >+Expire the added debarment on the passed date >+ >+=item B<-c|--confirm> >+ >+Confirm that the script should actually undertake the debarments >+ >+=back >+ >+=cut >+ >+use strict; >+use warnings; >+use Getopt::Long qw( GetOptions ); >+use Pod::Usage qw( pod2usage ); >+ >+use Koha::Script -cron; >+use Koha::Patrons; >+use Koha::Patron::Debarments; >+ >+use C4::Log qw( cronlogaction ); >+ >+my ( $help, $confirm, $message, $expiration, $file ); >+GetOptions( >+ 'h|help' => \$help, >+ 'c|confirm:s' => \$confirm, >+ 'm|message:s' => \$message, >+ 'f|file:s' => \$file, >+ 'e|expiration:s' => \$expiration, >+) || pod2usage(2); >+pod2usage(1) if $help; >+pod2usage(1) unless ( $confirm && ( $message || $file )); >+ >+cronlogaction(); >+my $badBorrowers = Koha::Patrons->filter_by_amount_owed( { more_than => 0 } ); >+$message = getMessageContent(); >+ >+while ( my $bb = $badBorrowers->next ) { >+ >+ #Don't crash, but keep debarring as long as you can! >+ eval { >+ my $success = Koha::Patron::Debarments::AddDebarment( >+ { >+ borrowernumber => $bb->borrowernumber, >+ expiration => $expiration, >+ type => 'MANUAL', >+ comment => $message, >+ } >+ ); >+ }; >+ if ($@) { >+ print $@. "\n"; >+ } >+} >+ >+sub getMessageContent { >+ return $message if ($message); >+ open( my $FH, "<:encoding(UTF-8)", $file ) or die "$!\n"; >+ my @msg = <$FH>; >+ close $FH; >+ return join( "", @msg ); >+} >+ >+1; >+ >+__END__ >diff --git a/misc/debarrBorrowersWithFines.pl b/misc/debarrBorrowersWithFines.pl >deleted file mode 100644 >index fb46a6f3517..00000000000 >--- a/misc/debarrBorrowersWithFines.pl >+++ /dev/null >@@ -1,91 +0,0 @@ >-#!/usr/bin/perl >- >-use Modern::Perl; >-use Getopt::Long; >- >-use C4::Accounts; >-use Koha::Patrons; >-use Koha::Patron::Debarments; >- >-my ($help, $confirm, $message, $expiration, $file); >-GetOptions( >- 'h|help' => \$help, >- 'c|confirm:s' => \$confirm, >- 'm|message:s' => \$message, >- 'f|file:s' => \$file, >- 'e|expiration:s' => \$expiration, >-); >- >-my $HELP = <<HELP; >- >-debarrBorrowersWithFines.pl >- >-Creates a debarment for all Borrowers who have fines. >- >- -h --help This friendly reminder! >- >- -c --confirm Confirm that you want to make your Patrons MAD by barring >- them from your library because they have ANY unpaid fines. >- >- -m --message MANDATORY. The description of the debarment visible to the end-user. >- or >- -f --messagefile MANDATORY. The file from which to read the message content. >- >- -e --expiration OPTIONAL. When does the debarment expire? >- As ISO8601 date, eg '2015-12-31' >- >- >-EXAMPLE: >- >- debarrBorrowersWithFines.pl --confirm -m "This is a description of you bad deeds" >-That did almost work. >- >- debarrBorrowersWithFines.pl -c MAD -m "You didn't play by our rules!" -e '2015-12-31' >- debarrBorrowersWithFines.pl -c MAD -f "/home/koha/kohaclone/messagefile" >-This works. Always RTFM. >- >-HELP >- >-if ($help) { >- print $HELP; >- exit 0; >-} >-elsif (not($confirm) || $confirm ne 'MAD' || (not($message || $file) )) { >- print $HELP; >- exit 1; >-} >-elsif (not($file) && not(length($message) > 20)) { >- print $HELP; >- print "\nYour --message is too short. A proper message to your end-users must be longer than 20 characters.\n"; >- exit 1; >-} >- >-my $badBorrowers = Koha::Patrons->search->search_patrons_with_unpaid_fines(); >-$message = getMessageContent(); >- >-foreach my $bb (@$badBorrowers) { >- #Don't crash, but keep debarring as long as you can! >- eval { >- my $success = Koha::Patron::Debarments::AddDebarment({ >- borrowernumber => $bb->{borrowernumber}, >- expiration => $expiration, >- type => 'MANUAL', >- comment => $message, >- }); >- }; >- if ($@) { >- print $@."\n"; >- } >-} >- >-=head getMessageContent >-Gets either the textual message or slurps a file. >-=cut >- >-sub getMessageContent { >- return $message if ($message); >- open(my $FH, "<:encoding(UTF-8)", $file) or die "$!\n"; >- my @msg = <$FH>; >- close $FH; >- return join("",@msg); >-} >\ No newline at end of file >-- >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