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

(-)a/Koha/BackgroundJob/MARCImportCommitBatch.pm (-5 / +4 lines)
Lines 84-94 sub process { Link Here
84
                progress_callback => sub { my $job_progress = shift; $self->progress($job_progress)->store },
84
                progress_callback => sub { my $job_progress = shift; $self->progress($job_progress)->store },
85
            }
85
            }
86
            );
86
            );
87
        my $count = $num_added + $num_updated;
87
        my $count = $num_added + $num_updated + $num_ignored;
88
        if ($count) {
88
        $self->set( { progress => $count } );
89
            $self->set( { progress => $count, size => $count } );
89
        if ( $count != $size ) {
90
        } else {    # TODO Refine later
90
            $self->set( { status => 'failed' } );
91
            $self->set( { progress => 0, status => 'failed' } );
92
        }
91
        }
93
    } catch {
92
    } catch {
94
        warn $_;
93
        warn $_;
(-)a/t/db_dependent/Koha/BackgroundJob/MARCImportCommitBatch.t (-2 / +40 lines)
Lines 17-24 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::MockModule;
20
use Test::NoWarnings;
21
use Test::NoWarnings;
21
use Test::More tests => 2;
22
use Test::More tests => 3;
22
23
23
use Koha::Database;
24
use Koha::Database;
24
use Koha::BackgroundJobs;
25
use Koha::BackgroundJobs;
Lines 51-53 subtest 'enqueue() tests' => sub { Link Here
51
52
52
    $schema->storage->txn_rollback;
53
    $schema->storage->txn_rollback;
53
};
54
};
54
- 
55
56
subtest 'process() tests' => sub {
57
58
    plan tests => 4;
59
60
    $schema->storage->txn_begin;
61
62
    my $batch_return  = [];
63
    my $output_module = Test::MockModule->new('Koha::BackgroundJob::MARCImportCommitBatch');
64
    $output_module->mock(
65
        'BatchCommitRecords',
66
        sub {
67
            return @{$batch_return};
68
        }
69
    );
70
    my $import_batch = $builder->build_object( { class => 'Koha::ImportBatches' } );
71
72
    # Add two records
73
    $builder->build_object( { class => 'Koha::Import::Records', value => { import_batch_id => $import_batch->id } } );
74
    $builder->build_object( { class => 'Koha::Import::Records', value => { import_batch_id => $import_batch->id } } );
75
76
    my $job_id = Koha::BackgroundJob::MARCImportCommitBatch->new->enqueue( { import_batch_id => $import_batch->id } );
77
    my $job    = Koha::BackgroundJobs->find($job_id)->_derived_class;
78
79
    @{$batch_return} = ( 0, 0, 0, 0, 0, 2 );
80
    $job->process( { import_batch_id => $import_batch->id } );
81
    $job->discard_changes;
82
    is( $job->status, 'finished', 'A job where all records are ignored is a success' );
83
84
    $job->status('new')->store;
85
    @{$batch_return} = ( 1, 1, 0, 0, 0, 1 );
86
    $job->process( { import_batch_id => $import_batch->id } );
87
    $job->discard_changes;
88
    is( $job->status,   'failed', 'A job where the record counts do not match is failed' );
89
    is( $job->size,     '2',      'Size is based on number of records' );
90
    is( $job->progress, '3', 'Progress is the total number of records processed, including added/updated/ignored' );
91
    $schema->storage->txn_rollback;
92
};

Return to bug 40846