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:
sam marshall
2011-06-27 15:25:13 +02:00
committed by Eloy Lafuente (stronk7)
parent 8e0733f4d8
commit a854bca3cf
5 changed files with 98 additions and 19 deletions
+11 -4
View File
@@ -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;