Skip to content

Commit

Permalink
Merge branch 'MDL-43421-27' of git://github.com/mr-russ/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_27_STABLE
  • Loading branch information
stronk7 committed Jan 26, 2015
2 parents cccb0c0 + b2fb93f commit 73502d6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/datalib.php
Expand Up @@ -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 ;-)
Expand Down

0 comments on commit 73502d6

Please sign in to comment.