From 4340a83ae8ec0476823b6c42dd1297977f2864ad Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 11 Nov 2003 16:13:57 +0000 Subject: [PATCH] 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! --- mod/quiz/db/mysql.php | 22 ++++++++++++++++++++++ mod/quiz/db/postgres7.php | 22 ++++++++++++++++++++++ mod/quiz/version.php | 2 +- version.php | 2 +- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index 6729c19780..4a09717559 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -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."
"; + 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; } diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index 13ca997b41..6997247cd0 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -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."
"; + 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; } diff --git a/mod/quiz/version.php b/mod/quiz/version.php index c3d5ec9e1c..353d0cc356 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -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)? ?> diff --git a/version.php b/version.php index c2a12eb3f8..a9137aac78 100644 --- a/version.php +++ b/version.php @@ -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 -- 2.39.5