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

(-)a/Koha/BackgroundJob/CreateEHoldingsFromBiblios.pm (-4 / +11 lines)
Lines 66-71 sub process { Link Here
66
    my @record_ids = @{ $args->{record_ids} };
66
    my @record_ids = @{ $args->{record_ids} };
67
    my $package_id = $args->{package_id};
67
    my $package_id = $args->{package_id};
68
68
69
    my $report = {
70
        total_records => scalar @record_ids,
71
        total_success => 0,
72
    };
73
69
    my $package = Koha::ERM::EHoldings::Packages->find($package_id);
74
    my $package = Koha::ERM::EHoldings::Packages->find($package_id);
70
    unless ( $package ) {
75
    unless ( $package ) {
71
        push @messages, {
76
        push @messages, {
Lines 73-84 sub process { Link Here
73
            code => 'package_do_not_exist',
78
            code => 'package_do_not_exist',
74
            package_id => $package_id,
79
            package_id => $package_id,
75
        };
80
        };
81
82
        my $data = $self->decoded_data;
83
        $data->{messages} = \@messages;
84
        $data->{report} = $report;
85
86
        return $self->finish( $data );
76
    }
87
    }
77
88
78
    my $report = {
79
        total_records => scalar @record_ids,
80
        total_success => 0,
81
    };
82
    my $fix_coverage = sub {
89
    my $fix_coverage = sub {
83
        my $coverage = shift || q{};
90
        my $coverage = shift || q{};
84
        my @coverages = split '-', $coverage;
91
        my @coverages = split '-', $coverage;
(-)a/t/db_dependent/Koha/BackgroundJob/CreateEHoldingsFromBiblios.t (-25 / +65 lines)
Lines 49-79 subtest 'enqueue' => sub { Link Here
49
};
49
};
50
50
51
subtest 'process' => sub {
51
subtest 'process' => sub {
52
    plan tests => 1;
52
    plan tests => 2;
53
54
    $schema->storage->txn_begin;
55
53
56
    my $biblio = $builder->build_sample_biblio;
54
    subtest 'package_do_not_exist' => sub {
57
55
        plan tests => 2;
58
    my $package =
56
59
      Koha::ERM::EHoldings::Package->new( { name => 'a package' } )->store;
57
        $schema->storage->txn_begin;
60
58
61
    my $job = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new(
59
        my $biblio = $builder->build_sample_biblio;
62
        {
60
        my $package =
63
            status => 'new',
61
          Koha::ERM::EHoldings::Package->new( { name => 'a package' } )->store;
64
            type   => 'create_eholdings_from_biblios',
62
65
            size   => 1,
63
        my $job = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new(
66
        }
64
            {
67
    )->store;
65
                status => 'new',
68
    $job = Koha::BackgroundJobs->find( $job->id );
66
                type   => 'create_eholdings_from_biblios',
69
    my $data = {
67
                size   => 1,
70
        record_ids => [ $biblio->biblionumber ],
68
            }
71
        package_id => $package->package_id,
69
        )->store;
70
        $job = Koha::BackgroundJobs->find( $job->id );
71
        my $data = {
72
            record_ids => [ $biblio->biblionumber ],
73
            package_id => $package->package_id,
74
        };
75
        my $json = $job->json->encode($data);
76
        $job->data($json)->store;
77
        $package->delete; # Delete the package
78
        $job->process($data);
79
        is( $job->report->{total_success}, 0 );
80
        is_deeply(
81
            $job->messages,
82
            [
83
                {
84
                    code       => "package_do_not_exist",
85
                    package_id => $package->package_id,
86
                    type       => "error"
87
                }
88
            ]
89
        );
72
    };
90
    };
73
    my $json = $job->json->encode($data);
74
    $job->data($json)->store;
75
    $job->process($data);
76
    is( $job->report->{total_success}, 1 );
77
91
78
    $schema->storage->txn_rollback;
92
    subtest 'all good' => sub {
93
        plan tests => 1;
94
95
        $schema->storage->txn_begin;
96
97
        my $biblio = $builder->build_sample_biblio;
98
        my $package =
99
          Koha::ERM::EHoldings::Package->new( { name => 'a package' } )->store;
100
101
        my $job = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new(
102
            {
103
                status => 'new',
104
                type   => 'create_eholdings_from_biblios',
105
                size   => 1,
106
            }
107
        )->store;
108
        $job = Koha::BackgroundJobs->find( $job->id );
109
        my $data = {
110
            record_ids => [ $biblio->biblionumber ],
111
            package_id => $package->package_id,
112
        };
113
        my $json = $job->json->encode($data);
114
        $job->data($json)->store;
115
        $job->process($data);
116
        is( $job->report->{total_success}, 1 );
117
118
        $schema->storage->txn_rollback;
119
    };
79
};
120
};
80
- 

Return to bug 32781