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

(-)a/Koha/BackgroundJob/MARCImportCommitBatch.pm (-2 / +11 lines)
Lines 20-25 use Try::Tiny; Link Here
20
20
21
use base 'Koha::BackgroundJob';
21
use base 'Koha::BackgroundJob';
22
22
23
use Koha::Database;
23
use Koha::Import::Records;
24
use Koha::Import::Records;
24
use C4::ImportBatch qw(
25
use C4::ImportBatch qw(
25
    BatchCommitRecords
26
    BatchCommitRecords
Lines 74-84 sub process { Link Here
74
            sub { my $job_progress = shift; $self->progress( $job_progress )->store },
75
            sub { my $job_progress = shift; $self->progress( $job_progress )->store },
75
            { skip_intermediate_commit => 1 },
76
            { skip_intermediate_commit => 1 },
76
        );
77
        );
78
        my $count = $num_added + $num_updated;
79
        if( $count ) {
80
            $self->set({ progress => $count, size => $count });
81
        } else { # TODO Refine later
82
            $self->set({ progress => 0, status => 'failed' });
83
        }
77
    }
84
    }
78
    catch {
85
    catch {
79
        warn $_;
86
        warn $_;
87
        Koha::Database->schema->storage->txn_rollback; # TODO BatchCommitRecords started a transaction
80
        die "Something terrible has happened!"
88
        die "Something terrible has happened!"
81
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
89
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
90
        $self->set({ progress => 0, status => 'failed' });
82
    };
91
    };
83
92
84
    my $report = {
93
    my $report = {
Lines 107-114 sub enqueue { Link Here
107
    my ( $self, $args) = @_;
116
    my ( $self, $args) = @_;
108
117
109
    $self->SUPER::enqueue({
118
    $self->SUPER::enqueue({
110
        job_size => 0, # unknown for now
119
        job_size => Koha::Import::Records->search({ import_batch_id => $args->{import_batch_id} })->count,
111
        job_args => $args
120
        job_args => $args,
112
    });
121
    });
113
}
122
}
114
123
(-)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 / +15 lines)
Lines 20-25 use Try::Tiny; Link Here
20
20
21
use base 'Koha::BackgroundJob';
21
use base 'Koha::BackgroundJob';
22
22
23
use Koha::Database;
23
use C4::Matcher;
24
use C4::Matcher;
24
use C4::ImportBatch qw(
25
use C4::ImportBatch qw(
25
    RecordsFromMARCXMLFile
26
    RecordsFromMARCXMLFile
Lines 87-94 sub process { Link Here
87
    my $matcher_failed   = 0;
88
    my $matcher_failed   = 0;
88
    my $matcher_code     = "";
89
    my $matcher_code     = "";
89
90
91
    my $schema = Koha::Database->new->schema;
90
    try {
92
    try {
91
        my $schema = Koha::Database->new->schema;
92
        $schema->storage->txn_begin;
93
        $schema->storage->txn_begin;
93
94
94
        my ( $errors, $marcrecords );
95
        my ( $errors, $marcrecords );
Lines 110-117 sub process { Link Here
110
111
111
        $self->size(scalar @$marcrecords)->store;
112
        $self->size(scalar @$marcrecords)->store;
112
113
113
        ( $batch_id, $num_valid, $num_items, @import_errors ) =
114
        ( $batch_id, $num_valid, $num_items, @import_errors ) = BatchStageMarcRecords(
114
          BatchStageMarcRecords(
115
            $record_type,                $encoding,
115
            $record_type,                $encoding,
116
            $marcrecords,                $filename,
116
            $marcrecords,                $filename,
117
            $marc_modification_template, $comments,
117
            $marc_modification_template, $comments,
Lines 123-130 sub process { Link Here
123
                    $job_progress /= 2;
123
                    $job_progress /= 2;
124
                }
124
                }
125
                $self->progress( int($job_progress) )->store;
125
                $self->progress( int($job_progress) )->store;
126
              }
126
            }
127
          );
127
        );
128
        if( $num_valid ) {
129
            $self->set({ progress => $num_valid, size => $num_valid });
130
        } else { # We must assume that something went wrong here
131
            $self->set({ progress => 0, status => 'failed' });
132
        }
128
133
129
        if ($profile_id) {
134
        if ($profile_id) {
130
            my $ibatch = Koha::ImportBatches->find($batch_id);
135
            my $ibatch = Koha::ImportBatches->find($batch_id);
Lines 155-162 sub process { Link Here
155
    }
160
    }
156
    catch {
161
    catch {
157
        warn $_;
162
        warn $_;
163
        $schema->storage->txn_rollback;
158
        die "Something terrible has happened!"
164
        die "Something terrible has happened!"
159
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
165
          if ( $_ =~ /Rollback failed/ );    # TODO Check test: Rollback failed
166
        $self->set({ progress => 0, status => 'failed' });
160
    };
167
    };
161
168
162
    my $report = {
169
    my $report = {
Lines 190-197 sub enqueue { Link Here
190
    my ( $self, $args) = @_;
197
    my ( $self, $args) = @_;
191
198
192
    $self->SUPER::enqueue({
199
    $self->SUPER::enqueue({
193
        job_size => 0, # unknown for now
200
        job_size => 0, # TODO Unknown for now?
194
        job_args => $args
201
        job_args => $args,
195
    });
202
    });
196
}
203
}
197
204
198
- 

Return to bug 27421