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

(-)a/C4/ImportBatch.pm (-1 / +10 lines)
Lines 542-547 sub BatchCommitRecords { Link Here
542
    my $batch_id = shift;
542
    my $batch_id = shift;
543
    my $framework = shift;
543
    my $framework = shift;
544
544
545
    my $schema = Koha::Database->schema;
546
545
    # optional callback to monitor status 
547
    # optional callback to monitor status 
546
    # of job
548
    # of job
547
    my $progress_interval = 0;
549
    my $progress_interval = 0;
Lines 581-591 sub BatchCommitRecords { Link Here
581
583
582
    my $rec_num = 0;
584
    my $rec_num = 0;
583
    my @biblio_ids;
585
    my @biblio_ids;
586
    $schema->txn_begin; # We commit in a transaction
584
    while (my $rowref = $sth->fetchrow_hashref) {
587
    while (my $rowref = $sth->fetchrow_hashref) {
585
        $record_type = $rowref->{'record_type'};
588
        $record_type = $rowref->{'record_type'};
589
586
        $rec_num++;
590
        $rec_num++;
591
587
        if ($progress_interval and (0 == ($rec_num % $progress_interval))) {
592
        if ($progress_interval and (0 == ($rec_num % $progress_interval))) {
588
            &$progress_callback($rec_num);
593
            # report progress and commit
594
            $schema->txn_commit;
595
            &$progress_callback( $rec_num );
596
            $schema->txn_begin;
589
        }
597
        }
590
        if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') {
598
        if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') {
591
            $num_ignored++;
599
            $num_ignored++;
Lines 710-715 sub BatchCommitRecords { Link Here
710
            SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored');
718
            SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored');
711
        }
719
        }
712
    }
720
    }
721
    $schema->txn_commit; # Commit final records that may not have hit callback threshold
713
    $sth->finish();
722
    $sth->finish();
714
723
715
    if ( @biblio_ids ) {
724
    if ( @biblio_ids ) {
(-)a/misc/commit_file.pl (-8 / +10 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use strict;
3
use Modern::Perl;
4
use warnings;
4
5
BEGIN {
6
    # find Koha's Perl modules
7
    # test carefully before changing this
8
    use FindBin ();
9
    eval { require "$FindBin::Bin/kohalib.pl" };
10
}
5
11
6
use Koha::Script;
12
use Koha::Script;
7
use C4::Context;
13
use C4::Context;
Lines 39-46 if ($list_batches) { Link Here
39
# in future, probably should tie to a real user account
45
# in future, probably should tie to a real user account
40
C4::Context->set_userenv(0, 'batch', 0, 'batch', 'batch', 'batch', 'batch');
46
C4::Context->set_userenv(0, 'batch', 0, 'batch', 'batch', 'batch', 'batch');
41
47
42
my $dbh = C4::Context->dbh;
43
$dbh->{AutoCommit} = 0;
44
if ($batch_number =~ /^\d+$/ and $batch_number > 0) {
48
if ($batch_number =~ /^\d+$/ and $batch_number > 0) {
45
    my $batch = GetImportBatch($batch_number);
49
    my $batch = GetImportBatch($batch_number);
46
    die "$0: import batch $batch_number does not exist in database\n" unless defined $batch;
50
    die "$0: import batch $batch_number does not exist in database\n" unless defined $batch;
Lines 53-59 if ($batch_number =~ /^\d+$/ and $batch_number > 0) { Link Here
53
            unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted";
57
            unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted";
54
        process_batch($batch_number);
58
        process_batch($batch_number);
55
    }
59
    }
56
    $dbh->commit();
57
} else {
60
} else {
58
    die "$0: please specify a numeric batch ID\n";
61
    die "$0: please specify a numeric batch ID\n";
59
}
62
}
Lines 105-111 sub revert_batch { Link Here
105
108
106
    print "... reverting batch -- please wait\n";
109
    print "... reverting batch -- please wait\n";
107
    my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored) =
110
    my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored) =
108
        BatchRevertRecords($import_batch_id, 100, \&print_progress_and_commit);
111
        BatchRevertRecords( $import_batch_id );
109
    print "... finished reverting batch\n";
112
    print "... finished reverting batch\n";
110
113
111
    print <<_SUMMARY_;
114
    print <<_SUMMARY_;
Lines 124-132 _SUMMARY_ Link Here
124
127
125
128
126
sub print_progress_and_commit {
129
sub print_progress_and_commit {
127
    my $recs = shift;
130
    my ( $recs, $schema ) = @_;
128
    print "... processed $recs records\n";
131
    print "... processed $recs records\n";
129
    $dbh->commit();
130
}
132
}
131
133
132
sub print_usage {
134
sub print_usage {
(-)a/tools/manage-marc-import.pl (-19 / +12 lines)
Lines 235-255 sub commit_batch { Link Here
235
    my ( $num_added, $num_updated, $num_items_added,
235
    my ( $num_added, $num_updated, $num_items_added,
236
        $num_items_replaced, $num_items_errored, $num_ignored );
236
        $num_items_replaced, $num_items_errored, $num_ignored );
237
    my $schema = Koha::Database->new->schema;
237
    my $schema = Koha::Database->new->schema;
238
    $schema->storage->txn_do(
238
    my $callback = sub { };
239
        sub {
239
    if ($runinbackground) {
240
            my $callback = sub { };
240
        $job = put_in_background($import_batch_id);
241
            if ($runinbackground) {
241
        $callback = progress_callback( $job );
242
                $job = put_in_background($import_batch_id);
242
    }
243
                $callback = progress_callback( $job, $dbh );
243
    (
244
            }
244
        $num_added, $num_updated, $num_items_added,
245
            (
245
        $num_items_replaced, $num_items_errored, $num_ignored
246
                $num_added, $num_updated, $num_items_added,
246
      )
247
                $num_items_replaced, $num_items_errored, $num_ignored
247
      = BatchCommitRecords( $import_batch_id, $framework, 50,
248
              )
248
        $callback );
249
              = BatchCommitRecords( $import_batch_id, $framework, 50,
250
                $callback );
251
        }
252
    );
253
249
254
    my $results = {
250
    my $results = {
255
        did_commit => 1,
251
        did_commit => 1,
Lines 281-287 sub revert_batch { Link Here
281
            my $callback = sub { };
277
            my $callback = sub { };
282
            if ($runinbackground) {
278
            if ($runinbackground) {
283
                $job = put_in_background($import_batch_id);
279
                $job = put_in_background($import_batch_id);
284
                $callback = progress_callback( $job, $dbh );
280
                $callback = progress_callback( $job );
285
            }
281
            }
286
            (
282
            (
287
                $num_deleted,       $num_errors, $num_reverted,
283
                $num_deleted,       $num_errors, $num_reverted,
Lines 347-357 sub put_in_background { Link Here
347
343
348
sub progress_callback {
344
sub progress_callback {
349
    my $job = shift;
345
    my $job = shift;
350
    my $dbh = shift;
351
    return sub {
346
    return sub {
352
        my $progress = shift;
347
        my $progress = shift;
353
        $job->progress($progress);
348
        $job->progress($progress);
354
        $dbh->commit();
355
    }
349
    }
356
}
350
}
357
351
358
- 

Return to bug 29325