From 666a322acb3f8ab9365ac9c0cf00e1dcd1b4fed8 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 Signed-off-by: Arthur Suzuki Signed-off-by: Kyle M Hall Signed-off-by: Fridolin Somers --- Koha/BackgroundJob.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index b8c010924d..b22da6d0a3 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; $self->set( -- 2.39.5