|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# |
| 4 |
# This file is part of Koha. |
| 5 |
# |
| 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. |
| 10 |
# |
| 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. |
| 15 |
# |
| 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>. |
| 18 |
|
| 19 |
use Modern::Perl; |
| 20 |
|
| 21 |
BEGIN { |
| 22 |
# find Koha's Perl modules |
| 23 |
# test carefully before changing this |
| 24 |
use FindBin; |
| 25 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
| 26 |
} |
| 27 |
|
| 28 |
use Getopt::Long; |
| 29 |
use Pod::Usage; |
| 30 |
|
| 31 |
use C4::Reserves; |
| 32 |
use C4::Log; |
| 33 |
use Koha::Holds; |
| 34 |
use Koha::Calendar; |
| 35 |
use Koha::DateUtils; |
| 36 |
use Koha::Libraries; |
| 37 |
|
| 38 |
cronlogaction(); |
| 39 |
|
| 40 |
=head1 NAME |
| 41 |
|
| 42 |
cancel_waiting_holds.pl |
| 43 |
|
| 44 |
=head1 SYNOPSIS |
| 45 |
|
| 46 |
cancel_waiting_holds.pl |
| 47 |
[-days][-library][-holidays] |
| 48 |
|
| 49 |
Options: |
| 50 |
-help brief help |
| 51 |
-days cancel holds waiting this many days |
| 52 |
-library [repeatable] limit to specified branch(es) |
| 53 |
-holidays skip holidays when calculating days waiting |
| 54 |
-v verbose |
| 55 |
|
| 56 |
head1 OPTIONS |
| 57 |
|
| 58 |
=over 8 |
| 59 |
|
| 60 |
=item B<-help> |
| 61 |
|
| 62 |
Print brief help and exit. |
| 63 |
|
| 64 |
=item B<-man> |
| 65 |
|
| 66 |
Print full documentation and exit. |
| 67 |
|
| 68 |
=item B<-days> |
| 69 |
|
| 70 |
Specify the number of days waiting upon which to cancel holds. |
| 71 |
|
| 72 |
=item B<-library> |
| 73 |
|
| 74 |
Repeatable option to specify which branchcode(s) to cancel holds for. |
| 75 |
|
| 76 |
=item B<-holidays> |
| 77 |
|
| 78 |
This switch specifies whether to count holidays as days waiting. Default is no. |
| 79 |
|
| 80 |
=back |
| 81 |
|
| 82 |
=cut |
| 83 |
|
| 84 |
my $help = 0; |
| 85 |
my $days; |
| 86 |
my @branchcodes; |
| 87 |
my $use_calendar = 0; |
| 88 |
my $verbose = 0; |
| 89 |
my $confirm = 0; |
| 90 |
|
| 91 |
GetOptions( |
| 92 |
'help|?' => \$help, |
| 93 |
'days=s' => \$days, |
| 94 |
'library=s' => \@branchcodes, |
| 95 |
'holidays' => \$use_calendar, |
| 96 |
'v' => \$verbose, |
| 97 |
'confirm' => \$confirm, |
| 98 |
) or pod2usage(1); |
| 99 |
pod2usage(1) if $help; |
| 100 |
|
| 101 |
unless ( defined $days ) { |
| 102 |
pod2usage( |
| 103 |
{ |
| 104 |
-exitval => 1, |
| 105 |
-msg => |
| 106 |
qq{\nError: You must specify a value for days waiting to cancel holds.\n}, |
| 107 |
} |
| 108 |
); |
| 109 |
} |
| 110 |
warn "Running in test mode, no actions will be taken" unless ($confirm); |
| 111 |
|
| 112 |
$verbose and warn "Looking for unfilled holds placed $days or more days ago\n"; |
| 113 |
|
| 114 |
unless ( scalar @branchcodes > 0 ) { |
| 115 |
my $branches = Koha::Libraries->search->get_column('branchcode'); |
| 116 |
while ( my $branch = $branches->next ) { |
| 117 |
push @branchcodes, $branch->branchcode; |
| 118 |
} |
| 119 |
} |
| 120 |
$verbose and warn "Running for branch(es): " . join( "|", @branchcodes ) . "\n"; |
| 121 |
|
| 122 |
foreach my $branch (@branchcodes) { |
| 123 |
|
| 124 |
my $holds = |
| 125 |
Koha::Holds->search( { branchcode => $branch } )->unfilled(); |
| 126 |
|
| 127 |
while ( my $hold = $holds->next ) { |
| 128 |
|
| 129 |
my $age = $hold->age( $use_calendar ); |
| 130 |
|
| 131 |
$verbose |
| 132 |
and warn "Hold #" |
| 133 |
. $hold->reserve_id |
| 134 |
. " has been unfilled for $age day(s)\n"; |
| 135 |
|
| 136 |
if ( $age >= $days ) { |
| 137 |
my $action = $confirm ? "Cancelling " : "Would have cancelled "; |
| 138 |
$verbose |
| 139 |
and warn $action |
| 140 |
. "reserve_id: " |
| 141 |
. $hold->reserve_id |
| 142 |
. " for borrower: " |
| 143 |
. $hold->borrowernumber |
| 144 |
. " on biblio: " |
| 145 |
. $hold->biblionumber . "\n"; |
| 146 |
CancelReserve( { reserve_id => $hold->reserve_id } ) if $confirm; |
| 147 |
} |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
} |