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 },
81 skip_intermediate_commit => 1,
83 my $count = $num_added + $num_updated;
85 $self->set({ progress => $count, size => $count });
86 } else { # TODO Refine later
87 $self->set({ progress => 0, status => 'failed' });
92 Koha::Database->schema->storage->txn_rollback; # TODO BatchCommitRecords started a transaction
93 die "Something terrible has happened!"
94 if ( $_ =~ /Rollback failed/ ); # Rollback failed
95 $self->set({ progress => 0, status => 'failed' });
99 num_added => $num_added,
100 num_updated => $num_updated,
101 num_items_added => $num_items_added,
102 num_items_replaced => $num_items_replaced,
103 num_items_errored => $num_items_errored,
104 num_ignored => $num_ignored,
105 import_batch_id => $import_batch_id,
107 my $data = $self->decoded_data;
108 $data->{messages} = \@messages;
109 $data->{report} = $report;
111 $self->finish($data);
121 my ( $self, $args) = @_;
123 $self->SUPER::enqueue({
124 job_size => Koha::Import::Records->search({ import_batch_id => $args->{import_batch_id} })->count,
126 job_queue => 'long_tasks',