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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2022-06-07 14:39:44 +02:00 committed by Tomas Cohen Arazi
parent 6c315c164d
commit 0f2425a243
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -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;
}