MDL-77837 cron: Ensure user is set when running tasks

We should be proactive in ensuring that the environment is clean when
running a task. We already ensure that we have a clean renderer and
other parts of the output chain, but we were not setting a clean user.

This change adds a call to setup the cron user before each task is
actually executed.
This commit is contained in:
Andrew Nicols 2023-04-04 09:25:04 +08:00
parent f8e2445513
commit 346cb39cff

View File

@ -248,6 +248,10 @@ function cron_run_inner_scheduled_task(\core\task\task_base $task) {
$predbqueries = null;
$predbqueries = $DB->perf_get_queries();
$pretime = microtime(1);
// Ensure that we have a clean session with the correct cron user.
cron_setup_user();
try {
get_mailer('buffer');
cron_prepare_core_renderer();
@ -346,6 +350,10 @@ function cron_run_inner_adhoc_task(\core\task\adhoc_task $task) {
}
cron_setup_user($user);
} else {
// No user specified, ensure that we have a clean session with the correct cron user.
cron_setup_user();
}
try {