Whenever a question is edited the version field is set to question_hash(), see bug 2958.

This commit is contained in:
gustav_delius
2006-04-10 22:10:32 +00:00
parent 9d4cbe5615
commit cbe20043b5
12 changed files with 42 additions and 18 deletions
+12
View File
@@ -1269,6 +1269,18 @@ function question_new_attempt_uniqueid() {
return $CFG->attemptuniqueid;
}
/* Creates a stamp that uniquely identifies this version of the question
*
* In future we want this to use a hash of the question data to guarantee that
* identical versions have the same version stamp.
*
* @param object $question
* @return string A unique version stamp
*/
function question_hash($question) {
return make_unique_id_code();
}
/// FUNCTIONS THAT SIMPLY WRAP QUESTIONTYPE METHODS //////////////////////////////////
+4
View File
@@ -1015,6 +1015,10 @@ function quiz_upgrade($oldversion) {
modify_database('', " INSERT INTO prefix_log_display VALUES ('quiz', 'continue attempt', 'quiz', 'name');");
}
if ($oldversion < 2006041001) {
table_column('question', 'version', 'version', 'varchar', 255);
}
return true;
}
+1 -1
View File
@@ -255,7 +255,7 @@ CREATE TABLE prefix_question (
qtype varchar(20) NOT NULL default '',
length int(10) unsigned NOT NULL default '1',
stamp varchar(255) NOT NULL default '',
version int(10) NOT NULL default '1',
version varchar(255) NOT NULL default '',
hidden int(1) unsigned NOT NULL default '0',
PRIMARY KEY (id),
KEY category (category)
+4
View File
@@ -1184,6 +1184,10 @@ function quiz_upgrade($oldversion) {
modify_database('', " INSERT INTO prefix_log_display VALUES ('quiz', 'continue attempt', 'quiz', 'name');");
}
if ($oldversion < 2006041001) {
table_column('question', 'version', 'version', 'varchar', 255);
}
return true;
}
+1 -1
View File
@@ -249,7 +249,7 @@ CREATE TABLE prefix_question (
qtype varchar(20) NOT NULL default '0',
length integer NOT NULL DEFAULT '1',
stamp varchar(255) NOT NULL default '',
version integer NOT NULL default '1',
version varchar(255) NOT NULL default '',
hidden integer NOT NULL default '0'
);
+1 -1
View File
@@ -5,7 +5,7 @@
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2006041000; // The (date) version of this module
$module->version = 2006041001; // The (date) version of this module
$module->requires = 2006022400; // Requires this Moodle version
$module->cron = 0; // How often should cron check this module (seconds)?
+3 -1
View File
@@ -91,7 +91,6 @@ class qformat_default {
$question->category = $this->category->id;
$question->stamp = make_unique_id_code(); // Set the unique code (not to be changed)
$question->version = 1; // Original version of this question
if (!$question->id = insert_record("question", $question)) {
error( get_string('cannotinsert','quiz') );
@@ -114,6 +113,9 @@ class qformat_default {
notify($result->notice);
return true;
}
// Give the question a unique version stamp determined by question_hash()
set_field('question', 'version', question_hash($question), 'id', $question->id);
}
return true;
}
+4 -1
View File
@@ -191,7 +191,10 @@ class qformat_aon extends qformat_default {
notify($result->notice);
}
/// Delete the old short-answer questions
// Give the question a unique version stamp determined by question_hash()
set_field('question', 'version', question_hash($question), 'id', $question->id);
/// Delete the old short-answer questions
execute_sql("DELETE FROM {$CFG->prefix}question WHERE id IN ($extractids)", false);
execute_sql("DELETE FROM {$CFG->prefix}question_shortanswer WHERE question IN ($extractids)", false);
+2 -1
View File
@@ -243,7 +243,6 @@ class qformat_coursetestmanager extends qformat_default {
echo "<hr /><p><b>$count</b>. ".stripslashes($question->questiontext)."</p>";
$question->category = $this->category->id;
$question->stamp = make_unique_id_code(); // Set the unique code (not to be changed)
$question->version = 1; // Original version of this question
if (!$question->id = insert_record("question", $question)) {
error("Could not insert new question!");
}
@@ -260,6 +259,8 @@ class qformat_coursetestmanager extends qformat_default {
$this->deletedatabase($filename);
return true;
}
// Give the question a unique version stamp determined by question_hash()
set_field('question', 'version', question_hash($question), 'id', $question->id);
}
$this->deletedatabase($filename);
return true;
+1 -1
View File
@@ -212,7 +212,7 @@
}
//Check if the question exists
//by category and stamp
//by category, stamp, and version
$question_exists = get_record ("question","category",$question->category,
"stamp",$question->stamp,"version",$question->version);
@@ -108,9 +108,6 @@ class embedded_cloze_qtype extends default_questiontype {
$question = qtype_multianswer_extract_question ($form->questiontext);
if (isset($authorizedquestion->id)) {
$question->id = $authorizedquestion->id;
$question->version = $form->version = $authorizedquestion->version;
} else {
$question->version = $form->version = 1;
}
+9 -8
View File
@@ -74,19 +74,15 @@ class default_questiontype {
$question->defaultgrade = $form->defaultgrade;
}
// Set the unique code
// TODO: set the stamp to a hash of the questiondata so that identical
// questions will get the same stamp. That will elliminate possible
// duplication during backup when questions get changed without changes
$question->stamp = make_unique_id_code();
if (!empty($question->id)) { // Question already exists
$question->version ++; // Update version number of question
// keep existing unique stamp code
$question->stamp = get_field('question', 'stamp', 'id', $question->id);
if (!update_record("question", $question)) {
error("Could not update question!");
}
} else { // Question is a new one
$question->version = 1;
// Set the unique code
$question->stamp = make_unique_id_code();
if (!$question->id = insert_record("question", $question)) {
error("Could not insert new question!");
}
@@ -114,6 +110,11 @@ class default_questiontype {
exit;
}
// Give the question a unique version stamp determined by question_hash()
if (!set_field('question', 'version', question_hash($question), 'id', $question->id)) {
error('Could not update question version field');
}
return $question;
}