I'm adding a patch to MDL-54751 to set the proper user when executing a adhoc task in background. I send both realuser and userid, cron_setup_user could accept a $realuser param and do something like what I'm pasting below.
This is the logic I am adding to course_delete_modules task should be replaced by cron_setup_user($user, $context, $realuser) (or something similar) if we end up working on this.
if ($this->get_custom_data()->userid !== $this->get_custom_data()->realuserid) {
|
$realuser = $DB->get_record('user', array('id' => $this->get_custom_data()->realuserid));
|
cron_setup_user($realuser);
|
\core\session\manager::loginas($this->get_custom_data()->userid, \context_system::instance(), false);
|
} else {
|
$user = $DB->get_record('user', array('id' => $this->get_custom_data()->userid));
|
cron_setup_user($user);
|
}
|
- Discovered while testing
-
MDL-54751 Recycle Bin - deleting large complex objects forces user to wait
- Closed