MDL-28021 Completion system can create inconsistent database rows
This change includes:
(1) update deletes older versions of inconsistent rows
(2) update drops one index and replaces it with a new unique index
(3) fixed to ensure that when it decides whether to insert or update
it uses current database state and not cached info
(4) unit tests updated to test #3
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
7cb1a84978
commit
f114cff65f
+11
-4
@@ -935,13 +935,20 @@ class completion_info {
|
||||
function internal_set_data($cm, $data) {
|
||||
global $USER, $SESSION, $DB;
|
||||
|
||||
if ($data->id) {
|
||||
// Has real (nonzero) id meaning that a database row exists
|
||||
$DB->update_record('course_modules_completion', $data);
|
||||
} else {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
if (!$data->id) {
|
||||
// Check there isn't really a row
|
||||
$data->id = $DB->get_field('course_modules_completion', 'id',
|
||||
array('coursemoduleid'=>$data->coursemoduleid, 'userid'=>$data->userid));
|
||||
}
|
||||
if (!$data->id) {
|
||||
// Didn't exist before, needs creating
|
||||
$data->id = $DB->insert_record('course_modules_completion', $data);
|
||||
} else {
|
||||
// Has real (nonzero) id meaning that a database row exists, update
|
||||
$DB->update_record('course_modules_completion', $data);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
|
||||
if ($data->userid == $USER->id) {
|
||||
$SESSION->completioncache[$cm->course][$cm->id] = $data;
|
||||
|
||||
Reference in New Issue
Block a user