From 13367d15d0d60aedc6b9dd38710115bd5d82775c Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Tue, 3 Jan 2023 23:24:00 +0000 Subject: [PATCH] Bug 32560: Cronjob to mark expired borrowers as lost their card Test plan: 1. Edit a borrower to have an expiration date in the past - also make sure they have 'Lost card' set to 'No' 2. Run the set_expired_lost.pl script: sudo koha-shell cd misc/cronjobs ./set_expired_lost.pl 3. Notice you get output saying the number of borrowers are to be changed 4. View the borrower account from #1 and notice they have a 'Lost card' value of 'Yes' 5. Run the set_expired_lost.pl script again and observe no output is printed to the terminal - this is because all expired borrowers have already been marked as lost. Sponsored-by: Dalton McCaughey Library, Australia Signed-off-by: David Nind --- misc/cronjobs/set_expired_lost.pl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 misc/cronjobs/set_expired_lost.pl diff --git a/misc/cronjobs/set_expired_lost.pl b/misc/cronjobs/set_expired_lost.pl new file mode 100755 index 0000000000..2dc17e4ed2 --- /dev/null +++ b/misc/cronjobs/set_expired_lost.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +use strict; +use C4::Context; + +my $dbh = C4::Context->dbh(); +my $DEBUG = 1; + +my $sth = $dbh->prepare("SELECT COUNT(*) AS amount FROM borrowers WHERE dateexpiry < NOW() AND lost <> 1"); +$sth->execute; +my $row = $sth->fetchrow_hashref(); + +# Output for email only if borrowers need changing +if ($row->{'amount'}) { + $DEBUG && print $row->{'amount'} . " borrowers to be changed"; +} +$sth->finish(); + +$sth = $dbh->prepare("UPDATE borrowers SET lost = 1 WHERE dateexpiry < NOW() AND lost <> 1"); + +$sth->execute; + +$sth->finish; +$dbh->disconnect; -- 2.30.2