From: tjhunt <tjhunt>
Date: Tue, 6 Jan 2009 05:20:21 +0000 (+0000)
Subject: question bank database: MDL-17608 Drop originalquestion field from the question_state... 
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=807a1a84270336d4a483b2c7b834d1118a04eda4;p=moodle.git

question bank database: MDL-17608 Drop originalquestion field from the question_states table - it was never used for anything.
---

diff --git a/lib/db/install.xml b/lib/db/install.xml
index 53faf8a99f..b11355d0fb 100644
--- a/lib/db/install.xml
+++ b/lib/db/install.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20081231" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20090106" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
@@ -1053,9 +1053,8 @@
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="attempt"/>
         <FIELD NAME="attempt" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="question"/>
-        <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="attempt" NEXT="originalquestion"/>
-        <FIELD NAME="originalquestion" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="question" NEXT="seq_number"/>
-        <FIELD NAME="seq_number" TYPE="int" LENGTH="6" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="originalquestion" NEXT="answer"/>
+        <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="attempt" NEXT="seq_number"/>
+        <FIELD NAME="seq_number" TYPE="int" LENGTH="6" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="question" NEXT="answer"/>
         <FIELD NAME="answer" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="seq_number" NEXT="timestamp"/>
         <FIELD NAME="timestamp" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="answer" NEXT="event"/>
         <FIELD NAME="event" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timestamp" NEXT="grade"/>
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php
index 2d8d76f7a3..c407436521 100644
--- a/lib/db/upgrade.php
+++ b/lib/db/upgrade.php
@@ -1218,6 +1218,21 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint($result, 2009010500);
     }
 
+    if ($result && $oldversion < 2009010600) {
+
+    /// Define field originalquestion to be dropped from question_states
+        $table = new xmldb_table('question_states');
+        $field = new xmldb_field('originalquestion');
+
+    /// Conditionally launch drop field originalquestion
+        if ($dbman->field_exists($table, $field)) {
+            $dbman->drop_field($table, $field);
+        }
+
+    /// Main savepoint reached
+        upgrade_main_savepoint($result, 2009010600);
+    }
+
     return $result;
 }
 
diff --git a/mod/quiz/restorelibpre15.php b/mod/quiz/restorelibpre15.php
index c267f43f0f..451fec6644 100644
--- a/mod/quiz/restorelibpre15.php
+++ b/mod/quiz/restorelibpre15.php
@@ -1458,7 +1458,6 @@
             //Now, build the RESPONSES record structure
             $response->attempt = $attempt_id;
             $response->question = backup_todb($res_info['#']['QUESTION']['0']['#']);
-            $response->originalquestion = backup_todb($res_info['#']['ORIGINALQUESTION']['0']['#']);
             $response->answer = backup_todb($res_info['#']['ANSWER']['0']['#']);
             $response->grade = backup_todb($res_info['#']['GRADE']['0']['#']);
 
@@ -1468,12 +1467,6 @@
                 $response->question = $question->new_id;
             }
 
-            //We have to recode the originalquestion field
-            $question = backup_getid($restore->backup_unique_code,"question",$response->originalquestion);
-            if ($question) {
-                $response->originalquestion = $question->new_id;
-            }
-
             //Set the raw_grade field (default to the existing grade one, no penalty in pre15 backups)
             $response->raw_grade = $response->grade;
 
diff --git a/question/backuplib.php b/question/backuplib.php
index 1118be6220..2d42c6f401 100644
--- a/question/backuplib.php
+++ b/question/backuplib.php
@@ -357,7 +357,6 @@
                 //Print state contents
                 fwrite ($bf,full_tag("ID",$level + 2,false,$state->id));
                 fwrite ($bf,full_tag("QUESTION",$level + 2,false,$state->question));
-                fwrite ($bf,full_tag("ORIGINALQUESTION",$level + 2,false,$state->originalquestion));
                 fwrite ($bf,full_tag("SEQ_NUMBER",$level + 2,false,$state->seq_number));
                 fwrite ($bf,full_tag("ANSWER",$level + 2,false,$state->answer));
                 fwrite ($bf,full_tag("TIMESTAMP",$level + 2,false,$state->timestamp));
diff --git a/question/restorelib.php b/question/restorelib.php
index 0ac7e145e4..8f528a7a9c 100644
--- a/question/restorelib.php
+++ b/question/restorelib.php
@@ -795,7 +795,6 @@
             $state = new stdClass;
             $state->attempt = $attempt_id;
             $state->question = backup_todb($res_info['#']['QUESTION']['0']['#']);
-            $state->originalquestion = backup_todb($res_info['#']['ORIGINALQUESTION']['0']['#']);
             $state->seq_number = backup_todb($res_info['#']['SEQ_NUMBER']['0']['#']);
             $state->answer = backup_todb($res_info['#']['ANSWER']['0']['#']);
             $state->timestamp = backup_todb($res_info['#']['TIMESTAMP']['0']['#']);
@@ -813,16 +812,6 @@
                 echo 'Could not recode question id '.$state->question.' for state '.$oldid.'<br />';
             }
 
-            //We have to recode the originalquestion field if it is nonzero
-            if ($state->originalquestion) {
-                $question = backup_getid($restore->backup_unique_code,"question",$state->originalquestion);
-                if ($question) {
-                    $state->originalquestion = $question->new_id;
-                } else {
-                    echo 'Could not recode originalquestion id '.$state->question.' for state '.$oldid.'<br />';
-                }
-            }
-
             //We have to recode the answer field
             //It depends of the question type !!
             //We get the question first
diff --git a/version.php b/version.php
index ea2a1582d8..d08cd028f7 100644
--- a/version.php
+++ b/version.php
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2009010500;  // YYYYMMDD   = date of the last version bump
+    $version = 2009010600;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20090106)';  // Human-friendly version name