From b9ea2b7ad5c93888ffcf70a1446de9488c903fa9 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 28 Feb 2007 17:19:04 +0000 Subject: [PATCH] Add a unique index to the question_numerical_units table, to prevent duplicate units being created. --- mod/quiz/db/install.xml | 5 ++++- mod/quiz/db/upgrade.php | 16 ++++++++++++++++ mod/quiz/version.php | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mod/quiz/db/install.xml b/mod/quiz/db/install.xml index 818e203806..f3e37aa0d8 100755 --- a/mod/quiz/db/install.xml +++ b/mod/quiz/db/install.xml @@ -1,5 +1,5 @@ - @@ -114,6 +114,9 @@ + + + diff --git a/mod/quiz/db/upgrade.php b/mod/quiz/db/upgrade.php index db8abd527b..d9b54353fb 100644 --- a/mod/quiz/db/upgrade.php +++ b/mod/quiz/db/upgrade.php @@ -32,6 +32,22 @@ function xmldb_quiz_upgrade($oldversion=0) { /// $result = result of "/lib/ddllib.php" function calls /// } + if ($result && $oldversion < 2007022800) { + /// Ensure that there are not existing duplicate entries in the database. + delete_records_select('question_numerical_units', "id > (SELECT MIN(iqnu.id) + FROM {$CFG->prefix}question_numerical_units iqnu + WHERE iqnu.question = {$CFG->prefix}question_numerical_units.question AND + iqnu.unit = {$CFG->prefix}question_numerical_units.unit)"); + + /// Define index question-unit (unique) to be added to question_numerical_units + $table = new XMLDBTable('question_numerical_units'); + $index = new XMLDBIndex('question-unit'); + $index->setAttributes(XMLDB_INDEX_UNIQUE, array('question', 'unit')); + + /// Launch add index question-unit + $result = $result && add_index($table, $index); + } + return $result; } diff --git a/mod/quiz/version.php b/mod/quiz/version.php index 05b940f7b1..30f67250df 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 = 2007020200; // The (date) version of this module +$module->version = 2007022800; // The (date) version of this module $module->requires = 2007020200; // Requires this Moodle version $module->cron = 0; // How often should cron check this module (seconds)? -- 2.39.5