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" };
28 use Getopt::Long qw( GetOptions );
29 use Pod::Usage qw( pod2usage );
31 use Koha::Script -cron;
33 use C4::Log qw( cronlogaction );
42 cancel_unfilled_holds.pl - script to delete unfilled holds after a given
47 cancel_unfilled_holds.pl [--days][--library][--holidays][--confirm][--verbose]
55 Print brief help and exit.
59 Specify the number of days waiting since a hold that remains unfilled was placed.
60 E.g. a value of 730 would cancel holds placed 2 years ago or more that have never been filled
64 Repeatable option to specify which branchcode(s) to cancel holds for.
68 This switch specifies whether to count holidays as days waiting. Default is no.
72 Without this option, the script will run in test mode, and only report what it
73 would have done if it were not running in test mode.
75 =item B<--verbose | -v>
93 'library=s' => \@branchcodes,
94 'holidays' => \$use_calendar,
95 'v|verbose' => \$verbose,
96 'confirm' => \$confirm,
98 pod2usage(1) if $help;
100 unless ( defined $days ) {
105 qq{\nError: You must specify a value for days waiting to cancel holds.\n},
109 warn "Running in test mode, no actions will be taken" unless ($confirm);
111 $verbose and warn "Looking for unfilled holds placed $days or more days ago\n";
113 @branchcodes = Koha::Libraries->search->get_column('branchcode') if !@branchcodes;
114 $verbose and warn "Running for branch(es): " . join( "|", @branchcodes ) . "\n";
116 foreach my $branch (@branchcodes) {
119 Koha::Holds->search( { branchcode => $branch } )->unfilled();
121 while ( my $hold = $holds->next ) {
123 my $age = $hold->age( $use_calendar );
128 . " has been unfilled for $age day(s)\n";
130 if ( $age >= $days ) {
131 my $action = $confirm ? "Cancelling " : "Would have cancelled ";
137 . $hold->borrowernumber
139 . $hold->biblionumber . "\n";
140 $hold->cancel if $confirm;