From 689ec49d6d03a548c37bb44c50f1b7ae46c05fd6 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 23 Mar 2022 15:47:38 -0300 Subject: [PATCH] Bug 30345: Make Koha::BackgroundJob->enqueue set borrowernumber=undef if no userenv This patch makes ->enqueue set undef if no userenv is provided. The CLI scripts will usually use Koha::Script and have this set to undef as well, but on the tests, there's usually no userenv set unless we need to test it. And as we are adding triggers everywhere, that will schedule background jobs, it means we would end up mocking userenv or the ->enqueue method everywhere and it will get messy. This patch just make it set undef. To test: 1. Apply the regression tests patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/BackgroundJob.t => FAIL: Wow, it explodes badly. Same as any test that happens to trigger a background job enqueuing. 3. Apply this patch 4. Repeat 2 => SUCCESS: Great, tests pass! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/BackgroundJob.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 46fa01e861..140b992e64 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -98,7 +98,7 @@ sub enqueue { my $job_size = $params->{job_size}; my $job_args = $params->{job_args}; - my $borrowernumber = C4::Context->userenv->{number}; # FIXME Handle non GUI calls + my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef; my $json_args = encode_json $job_args; my $job_id; $self->_result->result_source->schema->txn_do( -- 2.35.1