@@ -, +, @@ --- Koha/BackgroundJob.pm | 29 +++++++++++-------- .../Koha/BackgroundJobs/BatchUpdateBiblio.t | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) --- a/Koha/BackgroundJob.pm +++ a/Koha/BackgroundJob.pm @@ -166,18 +166,23 @@ sub process { $args ||= {}; - my $context = decode_json($self->context); - C4::Context->_new_userenv(-1); - C4::Context->interface( $context->{interface} ); - C4::Context->set_userenv( - $context->{number}, $context->{id}, - $context->{cardnumber}, $context->{firstname}, - $context->{surname}, $context->{branch}, - $context->{branchname}, $context->{flags}, - $context->{emailaddress}, undef, - $context->{desk_id}, $context->{desk_name}, - $context->{register_id}, $context->{register_name} - ); + if ( $self->context ) { + my $context = decode_json($self->context); + C4::Context->_new_userenv(-1); + C4::Context->interface( $context->{interface} ); + C4::Context->set_userenv( + $context->{number}, $context->{id}, + $context->{cardnumber}, $context->{firstname}, + $context->{surname}, $context->{branch}, + $context->{branchname}, $context->{flags}, + $context->{emailaddress}, undef, + $context->{desk_id}, $context->{desk_name}, + $context->{register_id}, $context->{register_name} + ); + } + else { + Koha::Logger->get->warn(qq{A background job didn't have context defined ($self->id)}); + } return $derived_class->process( $args ); } --- a/t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t +++ a/t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t @@ -52,7 +52,7 @@ subtest "Exceptions must be stringified" => sub { type => 'batch_biblio_record_modification', data => encode_json { record_ids => [ $biblio->biblionumber ], - } + }, } )->store; $job = Koha::BackgroundJobs->find( $job->id ); --