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

(-)a/Koha/BackgroundJob.pm (-12 / +17 lines)
Lines 166-183 sub process { Link Here
166
166
167
    $args ||= {};
167
    $args ||= {};
168
168
169
    my $context = decode_json($self->context);
169
    if ( $self->context ) {
170
    C4::Context->_new_userenv(-1);
170
        my $context = decode_json($self->context);
171
    C4::Context->interface( $context->{interface} );
171
        C4::Context->_new_userenv(-1);
172
    C4::Context->set_userenv(
172
        C4::Context->interface( $context->{interface} );
173
        $context->{number},       $context->{id},
173
        C4::Context->set_userenv(
174
        $context->{cardnumber},   $context->{firstname},
174
            $context->{number},       $context->{id},
175
        $context->{surname},      $context->{branch},
175
            $context->{cardnumber},   $context->{firstname},
176
        $context->{branchname},   $context->{flags},
176
            $context->{surname},      $context->{branch},
177
        $context->{emailaddress}, undef,
177
            $context->{branchname},   $context->{flags},
178
        $context->{desk_id},      $context->{desk_name},
178
            $context->{emailaddress}, undef,
179
        $context->{register_id},  $context->{register_name}
179
            $context->{desk_id},      $context->{desk_name},
180
    );
180
            $context->{register_id},  $context->{register_name}
181
        );
182
    }
183
    else {
184
        Koha::Logger->get->warn("A background job didn't have context defined (" . $self->id . ")");
185
    }
181
186
182
    return $derived_class->process( $args );
187
    return $derived_class->process( $args );
183
}
188
}
(-)a/t/db_dependent/Koha/BackgroundJob.t (-2 / +20 lines)
Lines 28-36 use Koha::BackgroundJob::BatchUpdateItem; Link Here
28
use JSON qw( decode_json encode_json );
28
use JSON qw( decode_json encode_json );
29
29
30
use t::lib::Mocks;
30
use t::lib::Mocks;
31
use t::lib::Mocks::Logger;
31
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
32
use t::lib::Koha::BackgroundJob::BatchTest;
33
use t::lib::Koha::BackgroundJob::BatchTest;
33
34
35
my $logger  = t::lib::Mocks::Logger->new;
34
my $schema  = Koha::Database->new->schema;
36
my $schema  = Koha::Database->new->schema;
35
my $builder = t::lib::TestBuilder->new;
37
my $builder = t::lib::TestBuilder->new;
36
38
Lines 176-182 subtest 'start(), step() and finish() tests' => sub { Link Here
176
178
177
subtest 'process tests' => sub {
179
subtest 'process tests' => sub {
178
180
179
    plan tests => 4;
181
    plan tests => 5;
180
182
181
    $schema->storage->txn_begin;
183
    $schema->storage->txn_begin;
182
184
Lines 221-226 subtest 'process tests' => sub { Link Here
221
    is_deeply( C4::Context->userenv, $job_context, "Userenv set from job context on process" );
223
    is_deeply( C4::Context->userenv, $job_context, "Userenv set from job context on process" );
222
    is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" );
224
    is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" );
223
225
226
    # Manually add a job (->new->store) without context
227
    my $incomplete_job = t::lib::Koha::BackgroundJob::BatchTest->new(
228
        {   status         => 'new',
229
            size           => 1,
230
            borrowernumber => $patron->borrowernumber,
231
            type           => 'batch_test',
232
            data           => encode_json {
233
                a => 'a',
234
                b => 'b',
235
            },
236
        }
237
    )->store;
238
239
    $incomplete_job = Koha::BackgroundJobs->find( $incomplete_job->id );
240
    $incomplete_job->process();
241
    $logger->warn_is( "A background job didn't have context defined (" . $incomplete_job->id . ")" );
242
224
    $schema->storage->txn_rollback;
243
    $schema->storage->txn_rollback;
225
};
244
};
226
245
227
- 

Return to bug 30889