]> git.mjollnir.org Git - moodle.git/commitdiff
Whenever a question is edited the version field is set to question_hash(), see bug...
authorgustav_delius <gustav_delius>
Mon, 10 Apr 2006 22:10:32 +0000 (22:10 +0000)
committergustav_delius <gustav_delius>
Mon, 10 Apr 2006 22:10:32 +0000 (22:10 +0000)
12 files changed:
lib/questionlib.php
mod/quiz/db/mysql.php
mod/quiz/db/mysql.sql
mod/quiz/db/postgres7.php
mod/quiz/db/postgres7.sql
mod/quiz/version.php
question/format.php
question/format/aon/format.php
question/format/coursetestmanager/format.php
question/restorelib.php
question/type/multianswer/questiontype.php
question/type/questiontype.php

index 29fd4e6f446dfcd17c2bde498b0f54c591ac75d1..5e07530549f857bd3fe408c1f4eaf864bd57705c 100644 (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 //////////////////////////////////
 
index de3a5e708980e30e9175d662814176dabda9baaf..8aa670375e3219d0926427d8671c5324b3813dbe 100644 (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;
 }
 
index 8e80d11de1ea2f3bb8b41898e0bf5b01831bc225..cdf48f2fd2738db51bb5d722af4b3379bd585b61 100644 (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)
index 920ed58432423e6e859de6ad4ea0dae9b0307570..9902c38c46cc8fb8d91791a58d6e2ef613cabd07 100644 (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;
 }
 
index 1fa5e0f6b2b99c4815c0e14343c9ee9bcb822d7f..94baa168e38dea4cb1e78d4d8340208f7e0c6e27 100644 (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'
 );
 
index 201e21980f4d181c5f2eb666ff3c3fdd6297289d..da7a2881e4aa378da13c4848aff69639be08c024 100644 (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)?
 
index 8af4a93f48fc2ead6162bc67f32e1c08cb1ceb5d..200aa7be143de8d25fdf6c5a9d636b9a3317746b 100644 (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;
     }
index da2163e41bd9d324907524618cbc69ecabe2c291..e78f9775df5284fd18003838622933b1c44c2360 100644 (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);
index 86455599a057807cf65e274fa60cf2406d94eee5..2416f394af4934fb838bc3e7b94e0018e7a1ffd6 100755 (executable)
@@ -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;
index 0b7fedf42243e9fcecf38b3541ce98a6695b3ba1..da1e5b9a49249212a90fe9c1701a0eddf17213bd 100644 (file)
             }
 
             //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);
 
index 4adf038e391fb5469d30e9e10412b2bc9f00595a..01afd5263811a3dc257465921dcb74bc9bf5e98c 100644 (file)
@@ -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;
         }
 
 
index a50ff8a99451ef098db24fbfa1c5fd0013aabf50..3bed76d117afe927ffeff11d087f0e1bb6d5fea1 100644 (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;
     }