1 package Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
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>.
20 use JSON qw( encode_json decode_json );
27 qw(load_branches_to_pull_from TransportCostMatrix update_queue_for_biblio);
29 use base 'Koha::BackgroundJob';
33 Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue - Update the holds queue
34 for a specified list of biblios.
36 This is a subclass of Koha::BackgroundJob.
44 Returns a string representing the job type. In this case I<update_holds_queue_for_biblios>.
49 return 'update_holds_queue_for_biblios';
54 Perform the expected action.
59 my ( $self, $args ) = @_;
61 my $schema = Koha::Database->new->schema;
65 started_on => \'NOW()',
71 my @biblio_ids = @{ $args->{biblio_ids} };
74 total_biblios => scalar @biblio_ids,
78 my $use_transport_cost_matrix = C4::Context->preference("UseTransportCostMatrix");
79 my $transport_cost_matrix = $use_transport_cost_matrix ? TransportCostMatrix() : undef;
80 my $branches_to_use = load_branches_to_pull_from($use_transport_cost_matrix);
84 foreach my $biblio_id (@biblio_ids) {
87 $schema->storage->txn_begin;
89 my $result = update_queue_for_biblio(
91 biblio_id => $biblio_id,
92 branches_to_use => $branches_to_use,
94 transport_cost_matrix => $transport_cost_matrix
100 code => 'holds_queue_updated',
101 biblio_id => $biblio_id,
103 $report->{total_success}++;
105 $schema->storage->txn_commit;
112 code => 'holds_queue_update_error',
113 biblio_id => $biblio_id,
117 $schema->storage->txn_rollback;
120 $self->progress( $self->progress + 1 )->store;
123 my $job_data = decode_json $self->data;
124 $job_data->{messages} = \@messages;
125 $job_data->{report} = $report;
129 ended_on => \'NOW()',
130 data => encode_json $job_data,
131 status => 'finished',
143 my ( $self, $args ) = @_;
145 Koha::Exceptions::MissingParameter->throw(
146 "Missing biblio_ids parameter is mandatory")
147 unless exists $args->{biblio_ids};
149 my @biblio_ids = @{ $args->{biblio_ids} };
151 $self->SUPER::enqueue(
153 job_size => scalar @biblio_ids,
154 job_args => { biblio_ids => \@biblio_ids }
159 =head3 additional_report
161 Pass the biblio's title and patron's name
165 sub additional_report {
166 my ( $self, $args ) = @_;
168 my $messages = $self->messages;
169 for my $m (@$messages) {
170 $m->{biblio} = Koha::Biblios->find( $m->{biblio_id} );
172 return { report_messages => $messages };