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

(-)a/misc/maintenance/fix_holds_waiting_and_issued.pl (-1 / +95 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Script;
21
use C4::Context;
22
23
use Getopt::Long qw( GetOptions );
24
25
=head1 NAME
26
27
fix_holds_waiting_and_issued.pl - Revert waiting holds on items that are currently checked out
28
29
=head1 SYNOPSIS
30
31
fix_holds_waiting_and_issued.pl
32
33
=head1 DESCRIPTION
34
35
Sometimes it is possible to end up with items that are both checked out to a patron, and associated
36
with a hold waiting to be picked up by a different patron. This script finds those items and reverts
37
the waiting holds.
38
39
=over 8
40
41
=item B<--help>
42
43
Prints a brief usage message and exits.
44
45
=item B<-c>
46
47
Confirms this script should alter the found holds.
48
49
=back
50
51
=cut
52
53
my $help = 0;
54
my $confirm;
55
56
sub print_usage {
57
    print <<_USAGE_;
58
$0: Revert waiting holds on items that are currently checked out
59
60
Sometimes it is possible to end up with items that are both checked out to a patron, and associated
61
with a hold waiting to be picked up by a different patron. This script finds those items and reverts
62
the waiting holds.
63
64
Parameters:
65
  -c, --confirm           Confirm the script should make the changes
66
  -h, --help              Print out this help message.
67
_USAGE_
68
}
69
70
my $result = GetOptions(
71
    'help|h'    => \$help,
72
    'confirm|c' => \$confirm,
73
);
74
75
if ($help) {
76
    print_usage();
77
    exit 0;
78
}
79
80
my $dbh = C4::Context->dbh;
81
my $sth = $dbh->prepare(
82
    q{
83
    SELECT reserve_id FROM issues
84
    LEFT JOIN reserves USING ( itemnumber )
85
    WHERE found IS NOT NULL
86
}
87
);
88
$sth->execute();
89
90
while ( my $r = $sth->fetchrow_hashref ) {
91
    my $reserve_id = $r->{reserve_id};
92
93
    my $hold = Koha::Holds->find($reserve_id);
94
    $hold->revert_found();
95
}

Return to bug 41698