View | Details | Raw Unified | Return to bug 27421
Collapse All | Expand All

(-)a/Koha/BackgroundJob/MARCImportCommitBatch.pm (-10 / +15 lines)
Lines 65-83 sub process { Link Here
65
    my ( $num_added, $num_updated, $num_items_added,
65
    my ( $num_added, $num_updated, $num_items_added,
66
        $num_items_replaced, $num_items_errored, $num_ignored );
66
        $num_items_replaced, $num_items_errored, $num_ignored );
67
    try {
67
    try {
68
        my $size = Koha::Import::Records->search({ import_batch_id => $import_batch_id })->count;
68
        ( $num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored ) =
69
        $self->size($size)->store;
69
          BatchCommitRecords(
70
        (
70
            $import_batch_id, $frameworkcode, 50,
71
            $num_added, $num_updated, $num_items_added,
71
            sub { my $job_progress = shift; $self->progress( $job_progress )->store }
72
            $num_items_replaced, $num_items_errored, $num_ignored
72
        );
73
          )
73
        my $count = $num_added + $num_updated;
74
          = BatchCommitRecords( $import_batch_id, $frameworkcode, 50,
74
        if( $count ) {
75
            sub { my $job_progress = shift; $self->progress( $job_progress )->store } );
75
            $self->set({ progress => $count, size => $count });
76
        } else { # TODO Refine later
77
            $self->set({ progress => 0, status => 'failed' });
78
        }
76
    }
79
    }
77
    catch {
80
    catch {
78
        warn $_;
81
        warn $_;
82
        Koha::Database->schema->storage->txn_rollback; # TODO BatchCommitRecords started a transaction
79
        die "Something terrible has happened!"
83
        die "Something terrible has happened!"
80
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
84
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
85
        $self->set({ progress => 0, status => 'failed' });
81
    };
86
    };
82
87
83
    my $report = {
88
    my $report = {
Lines 106-113 sub enqueue { Link Here
106
    my ( $self, $args) = @_;
111
    my ( $self, $args) = @_;
107
112
108
    $self->SUPER::enqueue({
113
    $self->SUPER::enqueue({
109
        job_size => 0, # unknown for now
114
        job_size => Koha::Import::Records->search({ import_batch_id => $args->{import_batch_id} })->count,
110
        job_args => $args
115
        job_args => $args,
111
    });
116
    });
112
}
117
}
113
118
(-)a/Koha/BackgroundJob/MARCImportRevertBatch.pm (-9 / +18 lines)
Lines 23-28 use base 'Koha::BackgroundJob'; Link Here
23
use C4::ImportBatch qw(
23
use C4::ImportBatch qw(
24
    BatchRevertRecords
24
    BatchRevertRecords
25
);
25
);
26
use Koha::Database;
27
use Koha::Import::Records;
26
28
27
=head1 NAME
29
=head1 NAME
28
30
Lines 64-80 sub process { Link Here
64
        $num_items_deleted, $num_ignored
66
        $num_items_deleted, $num_ignored
65
    );
67
    );
66
68
69
    my $schema = Koha::Database->new->schema;
67
    try {
70
    try {
68
        (
71
        $schema->storage->txn_begin;
69
            $num_deleted,       $num_errors, $num_reverted,
72
        ( $num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored ) =
70
            $num_items_deleted, $num_ignored
73
          BatchRevertRecords( $import_batch_id ); # TODO BatchRevertRecords still needs a progress_callback
71
        ) = BatchRevertRecords( $import_batch_id, 50,
74
        $schema->storage->txn_commit;
72
            sub { my $job_progress = shift; $self->progress( $job_progress )->store } );
75
76
        my $count = $num_deleted + $num_reverted;
77
        if( $count ) {
78
            $self->set({ progress => $count, size => $count });
79
        } else { # TODO Nothing happened? Refine later
80
            $self->set({ progress => 0, status => 'failed' });
81
        }
73
    }
82
    }
74
    catch {
83
    catch {
75
        warn $_;
84
        warn $_;
76
        die "Something terrible has happened!"
85
        $schema->storage->txn_rollback;
77
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
86
        $self->set({ progress => 0, status => 'failed' });
78
    };
87
    };
79
88
80
    my $report = {
89
    my $report = {
Lines 103-110 sub enqueue { Link Here
103
    my ( $self, $args) = @_;
112
    my ( $self, $args) = @_;
104
113
105
    $self->SUPER::enqueue({
114
    $self->SUPER::enqueue({
106
        job_size => 0, # unknown for now
115
        job_size => Koha::Import::Records->search({ import_batch_id => $args->{import_batch_id} })->count,
107
        job_args => $args
116
        job_args => $args,
108
    });
117
    });
109
}
118
}
110
119
(-)a/Koha/BackgroundJob/StageMARCForImport.pm (-9 / +14 lines)
Lines 87-94 sub process { Link Here
87
    my $matcher_failed   = 0;
87
    my $matcher_failed   = 0;
88
    my $matcher_code     = "";
88
    my $matcher_code     = "";
89
89
90
    my $schema = Koha::Database->new->schema;
90
    try {
91
    try {
91
        my $schema = Koha::Database->new->schema;
92
        $schema->storage->txn_begin;
92
        $schema->storage->txn_begin;
93
93
94
        my ( $errors, $marcrecords );
94
        my ( $errors, $marcrecords );
Lines 110-117 sub process { Link Here
110
110
111
        $self->size(scalar @$marcrecords)->store;
111
        $self->size(scalar @$marcrecords)->store;
112
112
113
        ( $batch_id, $num_valid, $num_items, @import_errors ) =
113
        ( $batch_id, $num_valid, $num_items, @import_errors ) = BatchStageMarcRecords(
114
          BatchStageMarcRecords(
115
            $record_type,                $encoding,
114
            $record_type,                $encoding,
116
            $marcrecords,                $filename,
115
            $marcrecords,                $filename,
117
            $marc_modification_template, $comments,
116
            $marc_modification_template, $comments,
Lines 123-130 sub process { Link Here
123
                    $job_progress /= 2;
122
                    $job_progress /= 2;
124
                }
123
                }
125
                $self->progress( int($job_progress) )->store;
124
                $self->progress( int($job_progress) )->store;
126
              }
125
            }
127
          );
126
        );
127
        if( $num_valid ) {
128
            $self->set({ progress => $num_valid, size => $num_valid });
129
        } else { # We must assume that something went wrong here
130
            $self->set({ progress => 0, status => 'failed' });
131
        }
128
132
129
        if ($profile_id) {
133
        if ($profile_id) {
130
            my $ibatch = Koha::ImportBatches->find($batch_id);
134
            my $ibatch = Koha::ImportBatches->find($batch_id);
Lines 155-162 sub process { Link Here
155
    }
159
    }
156
    catch {
160
    catch {
157
        warn $_;
161
        warn $_;
162
        $schema->storage->txn_rollback;
158
        die "Something terrible has happened!"
163
        die "Something terrible has happened!"
159
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
164
          if ( $_ =~ /Rollback failed/ );    # TODO Check test: Rollback failed
165
        $self->set({ progress => 0, status => 'failed' });
160
    };
166
    };
161
167
162
    my $report = {
168
    my $report = {
Lines 190-197 sub enqueue { Link Here
190
    my ( $self, $args) = @_;
196
    my ( $self, $args) = @_;
191
197
192
    $self->SUPER::enqueue({
198
    $self->SUPER::enqueue({
193
        job_size => 0, # unknown for now
199
        job_size => 0, # TODO Unknown for now?
194
        job_args => $args
200
        job_args => $args,
195
    });
201
    });
196
}
202
}
197
203
198
- 

Return to bug 27421