1 package Koha::BackgroundJob::BatchCancelHold;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use base 'Koha::BackgroundJob';
27 Koha::BackgroundJob::BatchCancelHold - Batch cancel holds
29 This is a subclass of Koha::BackgroundJob.
37 Define the job type of this job: batch_hold_cancel
42 return 'batch_hold_cancel';
47 Process the modification.
52 my ( $self, $args ) = @_;
54 if ( $self->status eq 'cancelled' ) {
60 my @hold_ids = @{ $args->{hold_ids} };
63 total_holds => scalar @hold_ids,
67 HOLD_IDS: for my $hold_id ( sort { $a <=> $b } @hold_ids ) {
71 my ( $hold, $patron, $biblio );
72 $hold = Koha::Holds->find($hold_id);
75 $patron = $hold->patron;
76 $biblio = $hold->biblio;
77 $hold->cancel( { cancellation_reason => $args->{reason} } );
80 if ( $error and $error != $hold or $@ ) {
84 code => 'hold_not_cancelled',
85 patron_id => defined $patron ? $patron->borrowernumber : '',
86 biblio_id => defined $biblio ? $biblio->biblionumber : '',
88 error => defined $hold
97 code => 'hold_cancelled',
98 patron_id => $patron->borrowernumber,
99 biblio_id => $biblio->biblionumber,
102 $report->{total_success}++;
107 my $data = $self->decoded_data;
108 $data->{messages} = \@messages;
109 $data->{report} = $report;
111 $self->finish( $data );
121 my ( $self, $args ) = @_;
123 # TODO Raise exception instead
124 return unless exists $args->{hold_ids};
126 my @hold_ids = @{ $args->{hold_ids} };
128 $self->SUPER::enqueue(
130 job_size => scalar @hold_ids,
131 job_args => { hold_ids => \@hold_ids, reason => $args->{reason} },
132 job_queue => 'long_tasks',
137 =head3 additional_report
139 Pass the biblio's title and patron's name
143 sub additional_report {
144 my ( $self, $args ) = @_;
146 my $messages = $self->messages;
147 for my $m ( @$messages ) {
148 $m->{patron} = Koha::Patrons->find($m->{patron_id});
149 $m->{biblio} = Koha::Biblios->find($m->{biblio_id});
151 return { report_messages => $messages };