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
Conflicts:
lib/db/upgrade.php
version.php
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
8e0733f4d8
commit
a854bca3cf
+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