View | Details | Raw Unified | Return to bug 32560
Collapse All | Expand All

(-)a/misc/cronjobs/set_expired_lost.pl (-16 / +41 lines)
Lines 1-24 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use strict;
3
# This file is part of Koha.
4
use C4::Context;
4
#
5
# Copyright (C) 2023 Catalyst IT
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
#-----------------------------------
5
20
6
my $dbh = C4::Context->dbh();
21
=head1 NAME
7
my $DEBUG = 1;
22
set_expired_lost.pl  cron script to mark expired borrowers as having list their card
23
                     (borrowers.lost = 1)
8
24
9
my $sth = $dbh->prepare("SELECT COUNT(*) AS amount FROM borrowers WHERE dateexpiry < NOW() AND lost <> 1");
25
=cut
10
$sth->execute;
26
11
my $row = $sth->fetchrow_hashref();
27
use Modern::Perl;
28
use Koha::Script -cron;
29
use Koha::Patrons;
30
use C4::Log qw( cronlogaction );
31
use Getopt::Long qw( GetOptions );
32
33
my $verbose;
34
GetOptions( 'v|verbose' => \$verbose );
35
36
my $command_line_options = join(" ",@ARGV);
37
cronlogaction({ info => $command_line_options });
38
39
my $patrons = Koha::Patrons->search({ dateexpiry => { '<' => \'NOW()' }, lost => { '<>' => 1 } });
12
40
13
# Output for email only if borrowers need changing
41
# Output for email only if borrowers need changing
14
if ($row->{'amount'}) {
42
if ($patrons->count) {
15
    $DEBUG && print $row->{'amount'} . " borrower(s) changed";
43
    print $patrons->count . " borrower(s) changed\n" if $verbose;
16
}
44
}
17
$sth->finish();
18
19
$sth = $dbh->prepare("UPDATE borrowers SET lost = 1 WHERE dateexpiry < NOW() AND lost <> 1");
20
45
21
$sth->execute;
46
foreach my $patron ($patrons) {
47
    $patron->update({ lost => 1 });
48
}
22
49
23
$sth->finish;
50
cronlogaction({ action => 'End', info => "COMPLETED" });
24
$dbh->disconnect;
25
- 

Return to bug 32560