Skip to content

Commit

Permalink
MDL-77837 cron: Ensure user is set when running tasks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrewnicols committed Apr 6, 2023
1 parent ca59050 commit 5837ade
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/cronlib.php
Expand Up @@ -247,6 +247,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();
Expand Down Expand Up @@ -333,6 +337,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 {
Expand Down

0 comments on commit 5837ade

Please sign in to comment.