Added some bug-fixing code from Eloy Lafuente that fixes a quiz problem.

What happens is that adding random questions used to set the timestamps
of these questions to the same value.  This is fine in normal operation,
but it stuffs up the backup of that course, overwriting the question.
When the course is restored, the missing questions cause quizzes to
have lots of red notices like "Question not found".

Anyhow, this patch should safely fix older installations that may have
these duplicate questions lying around.

THANKS ELOY!
This commit is contained in:
moodler 2003-11-11 16:13:57 +00:00
parent ec93fb5015
commit 4340a83ae8
4 changed files with 46 additions and 2 deletions

View File

@ -159,6 +159,28 @@ function quiz_upgrade($oldversion) {
}
}
if ($oldversion < 2003111100) {
$duplicates = get_records_sql("SELECT stamp as id,count(*) as cuenta
FROM {$CFG->prefix}quiz_questions
GROUP BY stamp
HAVING count(*)>1");
if ($duplicates) {
notify("You have some quiz questions with duplicate stamps IDs. Cleaning these up.");
foreach ($duplicates as $duplicate) {
$questions = get_records("quiz_questions","stamp",$duplicate->id);
$add = 1;
foreach ($questions as $question) {
echo "Changing question id $question->id stamp to ".$duplicate->id.$add."<br>";
set_field("quiz_questions","stamp",$duplicate->id.$add,"id",$question->id);
$add++;
}
}
} else {
notify("Checked your quiz questions for stamp duplication errors, but no problems were found.", "green");
}
}
return true;
}

View File

@ -114,6 +114,28 @@ function quiz_upgrade($oldversion) {
}
}
if ($oldversion < 2003111100) {
$duplicates = get_records_sql("SELECT stamp as id,count(*) as cuenta
FROM {$CFG->prefix}quiz_questions
GROUP BY stamp
HAVING count(*)>1");
if ($duplicates) {
notify("You have some quiz questions with duplicate stamps IDs. Cleaning these up.");
foreach ($duplicates as $duplicate) {
$questions = get_records("quiz_questions","stamp",$duplicate->id);
$add = 1;
foreach ($questions as $question) {
echo "Changing question id $question->id stamp to ".$duplicate->id.$add."<br>";
set_field("quiz_questions","stamp",$duplicate->id.$add,"id",$question->id);
$add++;
}
}
} else {
notify("Checked your quiz questions for stamp duplication errors, but no problems were found.", "green");
}
}
return true;
}

View File

@ -5,7 +5,7 @@
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2003082700; // The (date) version of this module
$module->version = 2003111100; // The (date) version of this module
$module->cron = 0; // How often should cron check this module (seconds)?
?>

View File

@ -5,7 +5,7 @@
// database to determine whether upgrades should
// be performed (see lib/db/*.php)
$version = 2003110400; // The current version is a date (YYYYMMDDXX)
$version = 2003111100; // The current version is a date (YYYYMMDDXX)
$release = "1.2 development"; // User-friendly version number