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 //////////////////////////////////
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;
}
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)
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;
}
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'
);
// 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)?
$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') );
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;
}
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);
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!");
}
$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;
}
//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);
$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;
}
$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!");
}
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;
}