4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 # find Koha's Perl modules
23 # test carefully before changing this
25 eval { require "$FindBin::Bin/../kohalib.pl" };
31 use Koha::Script -cron;
43 cancel_unfilled_holds.pl - script to delete unfilled holds after a given
48 cancel_unfilled_holds.pl [--days][--library][--holidays][--confirm][--verbose]
56 Print brief help and exit.
60 Specify the number of days waiting since a hold that remains unfilled was placed.
61 E.g. a value of 730 would cancel holds placed 2 years ago or more that have never been filled
65 Repeatable option to specify which branchcode(s) to cancel holds for.
69 This switch specifies whether to count holidays as days waiting. Default is no.
73 Without this option, the script will run in test mode, and only report what it
74 would have done if it were not running in test mode.
76 =item B<--verbose | -v>
94 'library=s' => \@branchcodes,
95 'holidays' => \$use_calendar,
96 'v|verbose' => \$verbose,
97 'confirm' => \$confirm,
99 pod2usage(1) if $help;
101 unless ( defined $days ) {
106 qq{\nError: You must specify a value for days waiting to cancel holds.\n},
110 warn "Running in test mode, no actions will be taken" unless ($confirm);
112 $verbose and warn "Looking for unfilled holds placed $days or more days ago\n";
114 @branchcodes = Koha::Libraries->search->get_column('branchcode') if !@branchcodes;
115 $verbose and warn "Running for branch(es): " . join( "|", @branchcodes ) . "\n";
117 foreach my $branch (@branchcodes) {
120 Koha::Holds->search( { branchcode => $branch } )->unfilled();
122 while ( my $hold = $holds->next ) {
124 my $age = $hold->age( $use_calendar );
129 . " has been unfilled for $age day(s)\n";
131 if ( $age >= $days ) {
132 my $action = $confirm ? "Cancelling " : "Would have cancelled ";
138 . $hold->borrowernumber
140 . $hold->biblionumber . "\n";
141 $hold->cancel if $confirm;