From 06d3b17f069c765d1c721d8c426f83b428c68514 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Mon, 9 Nov 2015 13:19:07 +0200 Subject: [PATCH] Bug 15157 - Cronjob to automatically debar Borrowers/Patrons with pending/unpaid fines/accountlines If your library wants to debar all Borrower who haven't paid their fines by the end of the year, this script will do that trick :) You can give the message from a file if the cronjob runner doesn't deal with quotes, or as a command-line parameter. --- misc/debarrBorrowersWithFines.pl | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 misc/debarrBorrowersWithFines.pl diff --git a/misc/debarrBorrowersWithFines.pl b/misc/debarrBorrowersWithFines.pl new file mode 100644 index 0000000000..5192bc06b7 --- /dev/null +++ b/misc/debarrBorrowersWithFines.pl @@ -0,0 +1,90 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Getopt::Long; + +use C4::Accounts; +use Koha::Borrower::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 = < 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 = C4::Accounts::GetAllBorrowersWithUnpaidFines(); +$message = getMessageContent(); + +foreach my $bb (@$badBorrowers) { + #Don't crash, but keep debarring as long as you can! + eval { + my $success = Koha::Borrower::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.20.1