1 package Koha::BackgroundJob::MARCImportCommitBatch;
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>.
21 use base 'Koha::BackgroundJob';
24 use Koha::Import::Records;
25 use C4::ImportBatch qw(
31 Koha::BackgroundJob::MARCImportCommitBatch - Commit records
33 This is a subclass of Koha::BackgroundJob.
41 Define the job type of this job: marc_import_commit_batch
46 return 'marc_import_commit_batch';
56 my ( $self, $args ) = @_;
60 my $import_batch_id = $args->{import_batch_id};
61 my $frameworkcode = $args->{frameworkcode};
66 my ( $num_added, $num_updated, $num_items_added,
67 $num_items_replaced, $num_items_errored, $num_ignored );
69 my $size = Koha::Import::Records->search({ import_batch_id => $import_batch_id })->count;
70 $self->size($size)->store;
71 ( $num_added, $num_updated, $num_items_added,
72 $num_items_replaced, $num_items_errored, $num_ignored ) =
74 $import_batch_id, $frameworkcode, 50,
75 sub { my $job_progress = shift; $self->progress( $job_progress )->store },
76 { skip_intermediate_commit => 1 },
78 my $count = $num_added + $num_updated;
80 $self->set({ progress => $count, size => $count });
81 } else { # TODO Refine later
82 $self->set({ progress => 0, status => 'failed' });
87 Koha::Database->schema->storage->txn_rollback; # TODO BatchCommitRecords started a transaction
88 die "Something terrible has happened!"
89 if ( $_ =~ /Rollback failed/ ); # Rollback failed
90 $self->set({ progress => 0, status => 'failed' });
94 num_added => $num_added,
95 num_updated => $num_updated,
96 num_items_added => $num_items_added,
97 num_items_replaced => $num_items_replaced,
98 num_items_errored => $num_items_errored,
99 num_ignored => $num_ignored,
100 import_batch_id => $import_batch_id,
102 my $data = $self->decoded_data;
103 $data->{messages} = \@messages;
104 $data->{report} = $report;
106 $self->finish($data);
116 my ( $self, $args) = @_;
118 $self->SUPER::enqueue({
119 job_size => Koha::Import::Records->search({ import_batch_id => $args->{import_batch_id} })->count,
121 queue => 'long_tasks',