Lines 85-140
my $help = 0;
Link Here
|
85 |
my $days; |
85 |
my $days; |
86 |
my @branchcodes; |
86 |
my @branchcodes; |
87 |
my $use_calendar = 0; |
87 |
my $use_calendar = 0; |
88 |
my $verbose = 0; |
88 |
my $verbose = 0; |
|
|
89 |
my $confirm = 0; |
89 |
|
90 |
|
90 |
GetOptions( |
91 |
GetOptions( |
91 |
'help|?' => \$help, |
92 |
'help|?' => \$help, |
92 |
'days=s' => \$days, |
93 |
'days=s' => \$days, |
93 |
'library=s' => \@branchcodes, |
94 |
'library=s' => \@branchcodes, |
94 |
'holidays' => \$use_calendar, |
95 |
'holidays' => \$use_calendar, |
95 |
'v' => \$verbose |
96 |
'v' => \$verbose, |
|
|
97 |
'confirm' => \$confirm, |
96 |
) or pod2usage(1); |
98 |
) or pod2usage(1); |
97 |
pod2usage(1) if $help; |
99 |
pod2usage(1) if $help; |
98 |
|
100 |
|
99 |
unless (defined $days) { |
101 |
unless ( defined $days ) { |
100 |
pod2usage({ |
102 |
pod2usage( |
|
|
103 |
{ |
101 |
-exitval => 1, |
104 |
-exitval => 1, |
102 |
-msg => qq{\nError: You must specify a value for days waiting to cancel holds.\n}, |
105 |
-msg => |
103 |
}); |
106 |
qq{\nError: You must specify a value for days waiting to cancel holds.\n}, |
|
|
107 |
} |
108 |
); |
104 |
} |
109 |
} |
105 |
$verbose and warn "Will cancel unfilled holds placed $days or more days ago\n"; |
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"; |
106 |
|
113 |
|
107 |
unless (scalar @branchcodes > 0 ) { |
114 |
unless ( scalar @branchcodes > 0 ) { |
108 |
my $branches = Koha::Libraries->search( {} , {columns => 'branchcode' } ); |
115 |
my $branches = Koha::Libraries->search->get_column('branchcode'); |
109 |
while ( my $branch = $branches->next ) { |
116 |
while ( my $branch = $branches->next ) { |
110 |
push @branchcodes, $branch->branchcode; |
117 |
push @branchcodes, $branch->branchcode; |
111 |
} |
118 |
} |
112 |
} |
119 |
} |
113 |
$verbose and warn "Running for branch(es): ".join("|",@branchcodes)."\n"; |
120 |
$verbose and warn "Running for branch(es): " . join( "|", @branchcodes ) . "\n"; |
114 |
|
121 |
|
115 |
foreach my $branch (@branchcodes){ |
122 |
foreach my $branch (@branchcodes) { |
116 |
|
123 |
|
117 |
my $holds = Koha::Holds->search( { found => undef , branchcode => $branch } ); |
124 |
my $holds = |
|
|
125 |
Koha::Holds->search( { found => undef, branchcode => $branch } ); |
118 |
|
126 |
|
119 |
while ( my $hold = $holds->next ){ |
127 |
while ( my $hold = $holds->next ) { |
120 |
|
128 |
|
121 |
my $days_waiting; |
129 |
my $days_waiting; |
122 |
my $today = DateTime->now(time_zone => C4::Context->tz ); |
130 |
my $today = dt_from_string(); |
123 |
|
131 |
|
124 |
if ( $use_calendar ) { |
132 |
if ($use_calendar) { |
125 |
my $calendar = Koha::Calendar->new( branchcode => $branch ); |
133 |
my $calendar = Koha::Calendar->new( branchcode => $branch ); |
126 |
$days_waiting = $calendar->days_between( dt_from_string( $hold->reservedate ), $today ); |
134 |
$days_waiting = |
|
|
135 |
$calendar->days_between( dt_from_string( $hold->reservedate ), |
136 |
$today ); |
127 |
} |
137 |
} |
128 |
else { |
138 |
else { |
129 |
$days_waiting = $today->delta_days( dt_from_string( $hold->reservedate ) ); |
139 |
$days_waiting = |
|
|
140 |
$today->delta_days( dt_from_string( $hold->reservedate ) ); |
130 |
} |
141 |
} |
131 |
$days_waiting = $days_waiting->in_units( 'days' ); |
142 |
$days_waiting = $days_waiting->in_units('days'); |
132 |
|
143 |
|
133 |
$verbose and warn "Hold #".$hold->reserve_id." has been waiting $days_waiting day(s)\n"; |
144 |
$verbose |
|
|
145 |
and warn "Hold #" |
146 |
. $hold->reserve_id |
147 |
. " has been waiting $days_waiting day(s)\n"; |
134 |
|
148 |
|
135 |
if ( $days_waiting >= $days ) { |
149 |
if ( $days_waiting >= $days ) { |
136 |
$verbose and warn "Cancelling reserve_id: ".$hold->reserve_id." for borrower: ".$hold->borrowernumber." on biblio: ".$hold->biblionumber."\n"; |
150 |
my $action = $confirm ? "Cancelling " : "Would have cancelled "; |
137 |
CancelReserve( {reserve_id => $hold->reserve_id } ); |
151 |
$verbose |
|
|
152 |
and warn $action |
153 |
. "reserve_id: " |
154 |
. $hold->reserve_id |
155 |
. " for borrower: " |
156 |
. $hold->borrowernumber |
157 |
. " on biblio: " |
158 |
. $hold->biblionumber . "\n"; |
159 |
CancelReserve( { reserve_id => $hold->reserve_id } ) if $confirm; |
138 |
} |
160 |
} |
139 |
|
161 |
|
140 |
} |
162 |
} |
141 |
- |
|
|