Merge branch 'MDL-43421' of git://github.com/mr-russ/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2015-01-26 10:24:51 +01:00
commit b646a710ba

View File

@ -1700,7 +1700,19 @@ function user_accesstime_log($courseid=0) {
$last->userid = $USER->id;
$last->courseid = $courseid;
$last->timeaccess = $timenow;
$DB->insert_record_raw('user_lastaccess', $last, false);
try {
$DB->insert_record_raw('user_lastaccess', $last, false);
} catch (dml_write_exception $e) {
// During a race condition we can fail to find the data, then it appears.
// If we still can't find it, rethrow the exception.
$lastaccess = $DB->get_field('user_lastaccess', 'timeaccess', array('userid' => $USER->id,
'courseid' => $courseid));
if ($lastaccess === false) {
throw $e;
}
// If we did find it, the race condition was true and another thread has inserted the time for us.
// We can just continue without having to do anything.
}
} else if ($timenow - $lastaccess < LASTACCESS_UPDATE_SECS) {
// no need to update now, it was updated recently in concurrent login ;-)