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

(-)a/misc/maintenance/fix_holds_waiting_and_issued.pl (-1 / +97 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 <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Script;
21
use Koha::Holds;
22
23
use C4::Context;
24
25
use Getopt::Long qw( GetOptions );
26
27
=head1 NAME
28
29
fix_holds_waiting_and_issued.pl - Revert waiting holds on items that are currently checked out
30
31
=head1 SYNOPSIS
32
33
fix_holds_waiting_and_issued.pl
34
35
=head1 DESCRIPTION
36
37
Sometimes it is possible to end up with items that are both checked out to a patron, and associated
38
with a hold waiting to be picked up by a different patron. This script finds those items and reverts
39
the waiting holds.
40
41
=over 8
42
43
=item B<--help>
44
45
Prints a brief usage message and exits.
46
47
=item B<-c>
48
49
Confirms this script should alter the found holds.
50
51
=back
52
53
=cut
54
55
my $help = 0;
56
my $confirm;
57
58
sub print_usage {
59
    print <<_USAGE_;
60
$0: Revert waiting holds on items that are currently checked out
61
62
Sometimes it is possible to end up with items that are both checked out to a patron, and associated
63
with a hold waiting to be picked up by a different patron. This script finds those items and reverts
64
the waiting holds.
65
66
Parameters:
67
  -c, --confirm           Confirm the script should make the changes
68
  -h, --help              Print out this help message.
69
_USAGE_
70
}
71
72
my $result = GetOptions(
73
    'help|h'    => \$help,
74
    'confirm|c' => \$confirm,
75
);
76
77
if ( $help || !$confirm ) {
78
    print_usage();
79
    exit 0;
80
}
81
82
my $dbh = C4::Context->dbh;
83
my $sth = $dbh->prepare(
84
    q{
85
    SELECT reserve_id FROM issues
86
    LEFT JOIN reserves USING ( itemnumber )
87
    WHERE found IS NOT NULL
88
}
89
);
90
$sth->execute();
91
92
while ( my $r = $sth->fetchrow_hashref ) {
93
    my $reserve_id = $r->{reserve_id};
94
95
    my $hold = Koha::Holds->find($reserve_id);
96
    $hold->revert_found();
97
}

Return to bug 41698