MDL-81991 core: Reload accessdata for dirty users in CLI mode

This commit is contained in:
Huong Nguyen 2024-06-26 16:26:21 +07:00
parent ad7fc69c25
commit ca7286c14c
No known key found for this signature in database
GPG Key ID: 40D88AB693A3E72A

View File

@ -979,6 +979,15 @@ function get_user_accessdata($userid, $preloadonly=false) {
$ACCESSLIB_PRIVATE->accessdatabyuser[$USER->id] = $USER->access;
}
// Unfortunately, we can't use the $ACCESSLIB_PRIVATE->dirtyusers array because it is not available in CLI.
// So we need to check if the user has been marked as dirty or not in the cache directly.
// This will add additional queries to the database, but it is the best we can do.
if (CLI_SCRIPT && !empty($ACCESSLIB_PRIVATE->accessdatabyuser[$userid])) {
if (get_cache_flag('accesslib/dirtyusers', $userid, $ACCESSLIB_PRIVATE->accessdatabyuser[$userid]['time'])) {
unset($ACCESSLIB_PRIVATE->accessdatabyuser[$userid]);
}
}
if (!isset($ACCESSLIB_PRIVATE->accessdatabyuser[$userid])) {
if (empty($userid)) {
if (!empty($CFG->notloggedinroleid)) {