From 6033bb9103f5062562441540e0ae18f839e1c487 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 7 Jun 2022 14:39:44 +0200 Subject: [PATCH] Bug 30889: Set userenv for background jobs We need to set the userenv when we process the jobs. It is useful for stats (at least) --- misc/background_jobs_worker.pl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl index 0027a820e7c..f10880d6ca9 100755 --- a/misc/background_jobs_worker.pl +++ b/misc/background_jobs_worker.pl @@ -121,6 +121,20 @@ sub process_job { die "fork failed!" unless defined $pid; - $job->process( $args ); + my $patron = Koha::Patrons->find($job->borrowernumber); + if ( $patron ) { + C4::Context->_new_userenv(-1); + C4::Context->set_userenv( + $patron->borrowernumber, $patron->userid, + $patron->cardnumber, $patron->firstname, + $patron->surname, $patron->branchcode, + $patron->library->branchname, $patron->flags + ); + $job->process( $args ); + C4::Context->_unset_userenv(-1); + } ese { + $job->process( $args ); + } + exit; } -- 2.25.1