1 package Koha::BackgroundJob::MARCImportRevertBatch;
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';
23 use C4::ImportBatch qw(
27 use Koha::Import::Records;
31 Koha::BackgroundJob::MARCImportRevertBatch - Revert a batch
33 This is a subclass of Koha::BackgroundJob.
41 Define the job type of this job: marc_import_revert_batch
46 return 'marc_import_revert_batch';
56 my ( $self, $args ) = @_;
60 my $import_batch_id = $args->{import_batch_id};
65 $num_deleted, $num_errors, $num_reverted,
66 $num_items_deleted, $num_ignored
69 my $schema = Koha::Database->new->schema;
71 $schema->storage->txn_begin;
72 ( $num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored ) =
73 BatchRevertRecords( $import_batch_id ); # TODO BatchRevertRecords still needs a progress_callback
74 $schema->storage->txn_commit;
76 my $count = $num_deleted + $num_reverted;
78 $self->set({ progress => $count, size => $count });
79 } else { # TODO Nothing happened? Refine later
80 $self->set({ progress => 0, status => 'failed' });
85 $schema->storage->txn_rollback;
86 $self->set({ progress => 0, status => 'failed' });
90 num_deleted => $num_deleted,
91 num_items_deleted => $num_items_deleted,
92 num_errors => $num_errors,
93 num_reverted => $num_reverted,
94 num_ignored => $num_ignored,
95 import_batch_id => $import_batch_id,
98 my $data = $self->decoded_data;
99 $data->{messages} = \@messages;
100 $data->{report} = $report;
102 $self->finish($data);
112 my ( $self, $args) = @_;
114 $self->SUPER::enqueue({
115 job_size => Koha::Import::Records->search({ import_batch_id => $args->{import_batch_id} })->count,
117 job_queue => 'long_tasks',