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

(-)a/C4/ImportBatch.pm (-21 / +17 lines)
Lines 509-536 sub BatchFindDuplicates { Link Here
509
509
510
=head2 BatchCommitRecords
510
=head2 BatchCommitRecords
511
511
512
  my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) =
512
    my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) =
513
        BatchCommitRecords($batch_id, $framework,
513
        BatchCommitRecords( $batch_id, $framework, $progress_interval, $progress_callback, $params );
514
        $progress_interval, $progress_callback);
514
515
    Parameter skip_intermediate_commit does what is says.
515
516
516
=cut
517
=cut
517
518
518
sub BatchCommitRecords {
519
sub BatchCommitRecords {
519
    my $batch_id = shift;
520
    my ( $batch_id, $framework, $progress_interval, $progress_callback, $params ) = @_;
520
    my $framework = shift;
521
    my $skip_intermediate_commit = $params->{skip_intermediate_commit};
522
    $progress_interval = 0 unless $progress_interval && $progress_interval =~ /^\d+$/;
523
    $progress_interval = 0 unless ref($progress_callback) eq 'CODE';
521
524
522
    my $schema = Koha::Database->schema;
525
    my $schema = Koha::Database->schema;
523
526
    $schema->txn_begin;
524
    # optional callback to monitor status 
527
    # NOTE: Moved this transaction to the front of the routine. Note that inside the while loop below
525
    # of job
528
    # transactions may be committed and started too again. The final commit is close to the end.
526
    my $progress_interval = 0;
527
    my $progress_callback = undef;
528
    if ($#_ == 1) {
529
        $progress_interval = shift;
530
        $progress_callback = shift;
531
        $progress_interval = 0 unless $progress_interval =~ /^\d+$/ and $progress_interval > 0;
532
        $progress_interval = 0 unless 'CODE' eq ref $progress_callback;
533
    }
534
529
535
    my $record_type;
530
    my $record_type;
536
    my $num_added = 0;
531
    my $num_added = 0;
Lines 560-566 sub BatchCommitRecords { Link Here
560
555
561
    my $rec_num = 0;
556
    my $rec_num = 0;
562
    my @biblio_ids;
557
    my @biblio_ids;
563
    $schema->txn_begin; # We commit in a transaction
564
    while (my $rowref = $sth->fetchrow_hashref) {
558
    while (my $rowref = $sth->fetchrow_hashref) {
565
        $record_type = $rowref->{'record_type'};
559
        $record_type = $rowref->{'record_type'};
566
560
Lines 568-576 sub BatchCommitRecords { Link Here
568
562
569
        if ($progress_interval and (0 == ($rec_num % $progress_interval))) {
563
        if ($progress_interval and (0 == ($rec_num % $progress_interval))) {
570
            # report progress and commit
564
            # report progress and commit
571
            $schema->txn_commit;
565
            $schema->txn_commit unless $skip_intermediate_commit;
572
            &$progress_callback( $rec_num );
566
            &$progress_callback( $rec_num );
573
            $schema->txn_begin;
567
            $schema->txn_begin unless $skip_intermediate_commit;
574
        }
568
        }
575
        if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') {
569
        if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') {
576
            $num_ignored++;
570
            $num_ignored++;
Lines 700-707 sub BatchCommitRecords { Link Here
700
        &$progress_callback($rec_num);
694
        &$progress_callback($rec_num);
701
    }
695
    }
702
696
703
    $schema->txn_commit; # Commit final records that may not have hit callback threshold
704
705
    $sth->finish();
697
    $sth->finish();
706
698
707
    if ( @biblio_ids ) {
699
    if ( @biblio_ids ) {
Lines 710-715 sub BatchCommitRecords { Link Here
710
    }
702
    }
711
703
712
    SetImportBatchStatus($batch_id, 'imported');
704
    SetImportBatchStatus($batch_id, 'imported');
705
706
    # Moved final commit to the end
707
    $schema->txn_commit;
708
713
    return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored);
709
    return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored);
714
}
710
}
715
711
(-)a/Koha/BackgroundJob/MARCImportCommitBatch.pm (-7 / +7 lines)
Lines 67-78 sub process { Link Here
67
    try {
67
    try {
68
        my $size = Koha::Import::Records->search({ import_batch_id => $import_batch_id })->count;
68
        my $size = Koha::Import::Records->search({ import_batch_id => $import_batch_id })->count;
69
        $self->size($size)->store;
69
        $self->size($size)->store;
70
        (
70
        ( $num_added, $num_updated, $num_items_added,
71
            $num_added, $num_updated, $num_items_added,
71
          $num_items_replaced, $num_items_errored, $num_ignored ) =
72
            $num_items_replaced, $num_items_errored, $num_ignored
72
          BatchCommitRecords(
73
          )
73
            $import_batch_id, $frameworkcode, 50,
74
          = BatchCommitRecords( $import_batch_id, $frameworkcode, 50,
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
        );
76
    }
77
    }
77
    catch {
78
    catch {
78
        warn $_;
79
        warn $_;
79
- 

Return to bug 27421