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};
62 my $overlay_frameworkcode = $args->{overlay_framework};
67 my ( $num_added, $num_updated, $num_items_added,
68 $num_items_replaced, $num_items_errored, $num_ignored );
70 my $size = Koha::Import::Records->search({ import_batch_id => $import_batch_id })->count;
71 $self->size($size)->store;
72 ( $num_added, $num_updated, $num_items_added,
73 $num_items_replaced, $num_items_errored, $num_ignored ) =
75 batch_id => $import_batch_id,
76 framework => $frameworkcode,
77 overlay_framework => $overlay_frameworkcode,
78 progress_interval => 50,
80 sub { my $job_progress = shift; $self->progress( $job_progress )->store },
82 my $count = $num_added + $num_updated;
84 $self->set({ progress => $count, size => $count });
85 } else { # TODO Refine later
86 $self->set({ progress => 0, status => 'failed' });
91 Koha::Database->schema->storage->txn_rollback; # TODO BatchCommitRecords started a transaction
92 die "Something terrible has happened!"
93 if ( $_ =~ /Rollback failed/ ); # Rollback failed
94 $self->set({ progress => 0, status => 'failed' });
98 num_added => $num_added,
99 num_updated => $num_updated,
100 num_items_added => $num_items_added,
101 num_items_replaced => $num_items_replaced,
102 num_items_errored => $num_items_errored,
103 num_ignored => $num_ignored,
104 import_batch_id => $import_batch_id,
106 my $data = $self->decoded_data;
107 $data->{messages} = \@messages;
108 $data->{report} = $report;
110 $self->finish($data);
120 my ( $self, $args) = @_;
122 $self->SUPER::enqueue({
123 job_size => Koha::Import::Records->search({ import_batch_id => $args->{import_batch_id} })->count,
125 job_queue => 'long_tasks',