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" };
42 cancel_unfilled_holds.pl
46 cancel_unfilled_holds.pl
47 [-days][-library][-holidays]
51 -days cancel holds placed this many days ago which have not been filled
52 -library [repeatable] limit to specified branch(es)
53 -holidays skip holidays when calculating days waiting
62 Print brief help and exit.
66 Print full documentation and exit.
70 Specify the number of days waiting since a hold that remains unfilled was placed.
71 E.g. a value of 730 would cancel holds placed 2 years ago or more that have never been filled
75 Repeatable option to specify which branchcode(s) to cancel holds for.
79 This switch specifies whether to count holidays as days waiting. Default is no.
95 'library=s' => \@branchcodes,
96 'holidays' => \$use_calendar,
98 'confirm' => \$confirm,
100 pod2usage(1) if $help;
102 unless ( defined $days ) {
107 qq{\nError: You must specify a value for days waiting to cancel holds.\n},
111 warn "Running in test mode, no actions will be taken" unless ($confirm);
113 $verbose and warn "Looking for unfilled holds placed $days or more days ago\n";
115 unless ( scalar @branchcodes > 0 ) {
116 my $branches = Koha::Libraries->search->get_column('branchcode');
117 while ( my $branch = $branches->next ) {
118 push @branchcodes, $branch->branchcode;
121 $verbose and warn "Running for branch(es): " . join( "|", @branchcodes ) . "\n";
123 foreach my $branch (@branchcodes) {
126 Koha::Holds->search( { branchcode => $branch } )->unfilled();
128 while ( my $hold = $holds->next ) {
130 my $age = $hold->age( $use_calendar );
135 . " has been unfilled for $age day(s)\n";
137 if ( $age >= $days ) {
138 my $action = $confirm ? "Cancelling " : "Would have cancelled ";
144 . $hold->borrowernumber
146 . $hold->biblionumber . "\n";
147 CancelReserve( { reserve_id => $hold->reserve_id } ) if $confirm;