From 0f2425a2433adc380b9bd06c7fdd20d5d7a268a6 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) Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- 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 0027a820e7..f10880d6ca 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.39.5