]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16058 - Remove obsolete quiz_question_versions table.
authortjhunt <tjhunt>
Fri, 15 Aug 2008 08:23:09 +0000 (08:23 +0000)
committertjhunt <tjhunt>
Fri, 15 Aug 2008 08:23:09 +0000 (08:23 +0000)
mod/quiz/backuplib.php
mod/quiz/db/install.xml
mod/quiz/db/upgrade.php
mod/quiz/lib.php
mod/quiz/restorelib.php
mod/quiz/restorelibpre15.php
mod/quiz/version.php

index 21a11d708151d5ba7bf43e87bc542c92593219b1..230777c38c5eaaedd307cf57259718cb9f267be0 100644 (file)
@@ -9,9 +9,9 @@
     //                        (CL,pk->id)
     //                            |
     //           -------------------------------------------------------------------
-    //           |               |                |                |               |
-    //           |          quiz_grades           |     quiz_question_versions     |
-    //           |      (UL,pk->id,fk->quiz)      |      (CL,pk->id,fk->quiz)      |
+    //           |               |                |                                |
+    //           |          quiz_grades           |                                |
+    //           |      (UL,pk->id,fk->quiz)      |                                |
     //           |                                |                                |
     //      quiz_attempts             quiz_question_instances                quiz_feedback
     //  (UL,pk->id,fk->quiz)       (CL,pk->id,fk->quiz,question)         (CL,pk->id,fk->quiz)
         $status = backup_quiz_question_instances($bf,$preferences,$quiz->id);
         //Now we print to xml quiz_feedback (Course Level)
         $status = backup_quiz_feedback($bf,$preferences,$quiz->id);
-        //Now we print to xml question_versions (Course Level)
-        $status = backup_quiz_question_versions($bf,$preferences,$quiz->id);
         //if we've selected to backup users info, then execute:
         //    - backup_quiz_grades
         //    - backup_quiz_attempts
         return $status;
     }
 
-    //Backup quiz_question_versions contents (executed from quiz_backup_mods)
-    function backup_quiz_question_versions ($bf,$preferences,$quiz) {
-        global $DB;
-        $status = true;
-
-        $quiz_question_versions = $DB->get_records('quiz_question_versions', array('quiz' =>$quiz),'id');
-        //If there are question_versions
-        if ($quiz_question_versions) {
-            //Write start tag
-            $status = fwrite ($bf,start_tag("QUESTION_VERSIONS",4,true));
-            //Iterate over each question_version
-            foreach ($quiz_question_versions as $que_ver) {
-                //Start question version
-                $status = fwrite ($bf,start_tag("QUESTION_VERSION",5,true));
-                //Print question_version contents
-                fwrite ($bf,full_tag("ID",6,false,$que_ver->id));
-                fwrite ($bf,full_tag("OLDQUESTION",6,false,$que_ver->oldquestion));
-                fwrite ($bf,full_tag("NEWQUESTION",6,false,$que_ver->newquestion));
-                fwrite ($bf,full_tag("ORIGINALQUESTION",6,false,$que_ver->originalquestion));
-                fwrite ($bf,full_tag("USERID",6,false,$que_ver->userid));
-                fwrite ($bf,full_tag("TIMESTAMP",6,false,$que_ver->timestamp));
-                //End question version
-                $status = fwrite ($bf,end_tag("QUESTION_VERSION",5,true));
-            }
-            //Write end tag
-            $status = fwrite ($bf,end_tag("QUESTION_VERSIONS",4,true));
-        }
-        return $status;
-    }
-
-
     //Backup quiz_grades contents (executed from quiz_backup_mods)
     function backup_quiz_grades ($bf,$preferences,$quiz) {
         global $DB;
index e9e6ad60ad8441932ffde2fefe65170d6474253e..f0f997fc885a01645f11f9bebe568c27dc38862e 100755 (executable)
@@ -80,7 +80,7 @@
         <INDEX NAME="userid" UNIQUE="false" FIELDS="userid"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="quiz_question_instances" COMMENT="The grade for a question in a quiz" PREVIOUS="quiz_grades" NEXT="quiz_question_versions">
+    <TABLE NAME="quiz_question_instances" COMMENT="The grade for a question in a quiz" PREVIOUS="quiz_grades" NEXT="quiz_feedback">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="quiz"/>
         <FIELD NAME="quiz" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="question"/>
         <KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="quiz"/>
       </KEYS>
     </TABLE>
-    <TABLE NAME="quiz_question_versions" COMMENT="quiz_question_versions table retrofitted from MySQL" PREVIOUS="quiz_question_instances" NEXT="quiz_feedback">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="quiz"/>
-        <FIELD NAME="quiz" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="oldquestion"/>
-        <FIELD NAME="oldquestion" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="quiz" NEXT="newquestion"/>
-        <FIELD NAME="newquestion" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="oldquestion" NEXT="originalquestion"/>
-        <FIELD NAME="originalquestion" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="newquestion" NEXT="userid"/>
-        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="originalquestion" NEXT="timestamp"/>
-        <FIELD NAME="timestamp" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="userid"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="quiz"/>
-        <KEY NAME="quiz" TYPE="foreign" FIELDS="quiz" REFTABLE="quiz" REFFIELDS="id" PREVIOUS="primary" NEXT="oldquestion"/>
-        <KEY NAME="oldquestion" TYPE="foreign" FIELDS="oldquestion" REFTABLE="question" REFFIELDS="id" PREVIOUS="quiz" NEXT="newquestion"/>
-        <KEY NAME="newquestion" TYPE="foreign" FIELDS="newquestion" REFTABLE="question" REFFIELDS="id" PREVIOUS="oldquestion" NEXT="originalquestion"/>
-        <KEY NAME="originalquestion" TYPE="foreign" FIELDS="originalquestion" REFTABLE="question" REFFIELDS="id" PREVIOUS="newquestion"/>
-      </KEYS>
-    </TABLE>
-    <TABLE NAME="quiz_feedback" COMMENT="Feedback given to students based on their overall score on the test" PREVIOUS="quiz_question_versions" NEXT="quiz_report">
+    <TABLE NAME="quiz_feedback" COMMENT="Feedback given to students based on their overall score on the test" PREVIOUS="quiz_grades" NEXT="quiz_report">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="quizid"/>
         <FIELD NAME="quizid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="feedbacktext"/>
index bb3b6ff6d1957ecf1c25042082099da256fda672..8bb84736502f5a98949b29896079ec0840ba71fc 100644 (file)
@@ -108,6 +108,17 @@ function xmldb_quiz_upgrade($oldversion=0) {
         upgrade_mod_savepoint($result, 2008072900, 'quiz');
     }
 
+    if ($result && $oldversion < 2008081500) {
+    /// Define table quiz_question_versions to be dropped
+        $table = new xmldb_table('quiz_question_versions');
+
+    /// Launch drop table for quiz_question_versions
+        $dbman->drop_table($table);
+
+    /// quiz savepoint reached
+        upgrade_mod_savepoint($result, 2008081500, 'quiz');
+    }
+
     return $result;
 }
 
index 2b0d456ccd417dfe3f00d8b19e5d784e0d8718a9..df5ce08c768ed0495b91fdf897578128f3f32323 100644 (file)
@@ -448,8 +448,6 @@ function quiz_grade_item_delete($quiz) {
 
 function quiz_get_participants($quizid) {
 /// Returns an array of users who have data in a given quiz
-/// (users with records in quiz_attempts and quiz_question_versions)
-
     global $CFG, $DB;
 
     //Get users from attempts
@@ -459,21 +457,8 @@ function quiz_get_participants($quizid) {
                                     WHERE a.quiz = ? and
                                           u.id = a.userid", array($quizid));
 
-    //Get users from question_versions
-    $us_versions = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
-                                    FROM {user} u,
-                                         {quiz_question_versions} v
-                                    WHERE v.quiz = ? and
-                                          u.id = v.userid", array($quizid));
-
-    //Add us_versions to us_attempts
-    if ($us_versions) {
-        foreach ($us_versions as $us_version) {
-            $us_attempts[$us_version->id] = $us_version;
-        }
-    }
     //Return us_attempts array (it contains an array of unique users)
-    return ($us_attempts);
+    return $us_attempts;
 
 }
 
index f5ed71eb8767299df0c48ae0ca0b419a5a2185f6..d84bedf35a295a26515afe1868816d68ae1400f8 100644 (file)
     //                           quiz
     //                        (CL,pk->id)
     //                            |
-    //           -------------------------------------------------------------------
-    //           |                    |                        |                    |
-    //           |               quiz_grades                   |        quiz_question_versions
-    //           |           (UL,pk->id,fk->quiz)              |         (CL,pk->id,fk->quiz)
+    //           -----------------------------------------------
+    //           |                    |                        |
+    //           |               quiz_grades                   |
+    //           |           (UL,pk->id,fk->quiz)              |
     //           |                                             |
     //      quiz_attempts                          quiz_question_instances
     //  (UL,pk->id,fk->quiz)                    (CL,pk->id,fk->quiz,question)
                 $status = quiz_question_instances_restore_mods($newid,$info,$restore);
                 //We have to restore the feedback now (course level table)
                 $status = quiz_feedback_restore_mods($newid, $info, $restore, $quiz);
-                //We have to restore the question_versions now (course level table)
-                $status = quiz_question_versions_restore_mods($newid,$info,$restore);
                 //Now check if want to restore user data and do it.
                 if (restore_userdata_selected($restore,'quiz',$mod->id)) {
                     //Restore quiz_attempts
         return $status;
     }
 
-    //This function restores the quiz_question_versions
-    function quiz_question_versions_restore_mods($quiz_id,$info,$restore) {
-        global $CFG, $USER, $DB;
-
-        $status = true;
-
-        //Get the quiz_question_versions array
-        if (!empty($info['MOD']['#']['QUESTION_VERSIONS'])) {
-            $versions = $info['MOD']['#']['QUESTION_VERSIONS']['0']['#']['QUESTION_VERSION'];
-        } else {
-            $versions = array();
-        }
-        
-        //Iterate over question_versions
-        for($i = 0; $i < sizeof($versions); $i++) {
-            $ver_info = $versions[$i];
-            //traverse_xmlize($ver_info);                                                                 //Debug
-            //print_object ($GLOBALS['traverse_array']);                                                  //Debug
-            //$GLOBALS['traverse_array']="";                                                              //Debug
-
-            //We'll need this later!!
-            $oldid = backup_todb($ver_info['#']['ID']['0']['#']);
-
-            //Now, build the QUESTION_VERSIONS record structure
-            $version = new stdClass;
-            $version->quiz = $quiz_id;
-            $version->oldquestion = backup_todb($ver_info['#']['OLDQUESTION']['0']['#']);
-            $version->newquestion = backup_todb($ver_info['#']['NEWQUESTION']['0']['#']);
-            $version->originalquestion = backup_todb($ver_info['#']['ORIGINALQUESTION']['0']['#']);
-            $version->userid = backup_todb($ver_info['#']['USERID']['0']['#']);
-            $version->timestamp = backup_todb($ver_info['#']['TIMESTAMP']['0']['#']);
-
-            //We have to recode the oldquestion field
-            $question = backup_getid($restore->backup_unique_code,"question",$version->oldquestion);
-            if ($question) {
-                $version->oldquestion = $question->new_id;
-            }
-
-            //We have to recode the newquestion field
-            $question = backup_getid($restore->backup_unique_code,"question",$version->newquestion);
-            if ($question) {
-                $version->newquestion = $question->new_id;
-            }
-
-            //We have to recode the originalquestion field
-            $question = backup_getid($restore->backup_unique_code,"question",$version->originalquestion);
-            if ($question) {
-                $version->newquestion = $question->new_id;
-            }
-
-            //We have to recode the userid field
-            $user = backup_getid($restore->backup_unique_code,"user",$version->userid);
-            if ($user) {
-                $version->userid = $user->new_id;
-            } else {  //Assign to current user
-                $version->userid = $USER->id;
-            }
-
-            //The structure is equal to the db, so insert the quiz_question_versions
-            $newid = $DB->insert_record ("quiz_question_versions",$version);
-
-            //Do some output
-            if (($i+1) % 10 == 0) {
-                if (!defined('RESTORE_SILENTLY')) {
-                    echo ".";
-                    if (($i+1) % 200 == 0) {
-                        echo "<br />";
-                    }
-                }
-                backup_flush(300);
-            }
-
-            if ($newid) {
-                //We have the newid, update backup_ids
-                backup_putid($restore->backup_unique_code,"quiz_question_versions",$oldid,
-                             $newid);
-            } else {
-                $status = false;
-            }
-        }
-
-        return $status;
-    }
-
     //This function restores the quiz_attempts
     function quiz_attempts_restore_mods($quiz_id,$info,$restore) {
         global $CFG, $DB;
index fcb5a6ff5f57727557a9ba7455f01286ded1e739..c267f43f0fbcc7b52a6e34936209716dc4e5bd9f 100644 (file)
@@ -9,16 +9,16 @@
     //                           quiz                                                      question_categories
     //                        (CL,pk->id)                                                   (CL,pk->id)
     //                            |                                                              |
-    //           -------------------------------------------------------------------             |
-    //           |                        |                    |                   |             |.......................................
-    //           |                        |                    |                   |             |                                      .
-    //           |                        |                    |                   |             |                                      .
-    //      quiz_attempts        quiz_grades       quiz_question_grades   quiz_question_versions |    ----question_datasets----    .
-    // (UL,pk->id, fk->quiz) (UL,pk->id,fk->quiz)  (CL,pk->id,fk->quiz)    (CL,pk->id,fk->quiz)  |    |  (CL,pk->id,fk->question,  |    .
-    //             |                                              |                      .       |    |   fk->dataset_definition)  |    .
-    //             |                                              |                      .       |    |                            |    .
-    //             |                                              |                      .       |    |                            |    .
-    //             |                                              |                      .       |    |                            |    .
+    //           -----------------------------------------------                                 |
+    //           |                        |                    |                                 |.......................................
+    //           |                        |                    |                                 |                                      .
+    //           |                        |                    |                                 |                                      .
+    //      quiz_attempts        quiz_grades       quiz_question_grades                          |    ----question_datasets----    .
+    // (UL,pk->id, fk->quiz) (UL,pk->id,fk->quiz)  (CL,pk->id,fk->quiz)                          |    |  (CL,pk->id,fk->question,  |    .
+    //             |                                              |                              |    |   fk->dataset_definition)  |    .
+    //             |                                              |                              |    |                            |    .
+    //             |                                              |                              |    |                            |    .
+    //             |                                              |                              |    |                            |    .
     //       quiz_responses                                       |                      question                       question_dataset_definitions
     //  (UL,pk->id, fk->attempt)----------------------------------------------------(CL,pk->id,fk->category,files)            (CL,pk->id,fk->category)
     //                                                                                           |                                      |
@@ -84,7 +84,6 @@
 
     // 2.-Standard module restore (Invoked via quiz_restore_mods). It includes this tables:
     //     - quiz
-    //     - quiz_question_versions
     //     - quiz_question_grades
     //     - quiz_attempts
     //     - quiz_grades
                              $mod->id, $newid);
                 //We have to restore the quiz_question_instances now (old quiz_question_grades, course level)
                 $status = quiz_question_instances_restore_pre15_mods($newid,$info,$restore);
-                //We have to restore the question_versions now (course level table)
-                $status = quiz_question_versions_restore_pre15_mods($newid,$info,$restore);
                 //Now check if want to restore user data and do it.
                 if (restore_userdata_selected($restore,'quiz',$mod->id)) {
                     //Restore quiz_attempts
         return $status;
     }
 
-    //This function restores the quiz_question_versions
-    function quiz_question_versions_restore_pre15_mods($quiz_id,$info,$restore) {
-        global $CFG, $USER, $DB;
-
-        $status = true;
-
-        //Get the quiz_question_versions array
-        $versions = $info['MOD']['#']['QUESTION_VERSIONS']['0']['#']['QUESTION_VERSION'];
-
-        //Iterate over question_versions
-        for($i = 0; $i < sizeof($versions); $i++) {
-            $ver_info = $versions[$i];
-            //traverse_xmlize($ver_info);                                                                 //Debug
-            //print_object ($GLOBALS['traverse_array']);                                                  //Debug
-            //$GLOBALS['traverse_array']="";                                                              //Debug
-
-            //We'll need this later!!
-            $oldid = backup_todb($ver_info['#']['ID']['0']['#']);
-
-            //Now, build the QUESTION_VERSIONS record structure
-            $version->quiz = $quiz_id;
-            $version->oldquestion = backup_todb($ver_info['#']['OLDQUESTION']['0']['#']);
-            $version->newquestion = backup_todb($ver_info['#']['NEWQUESTION']['0']['#']);
-            $version->userid = backup_todb($ver_info['#']['USERID']['0']['#']);
-            $version->timestamp = backup_todb($ver_info['#']['TIMESTAMP']['0']['#']);
-
-            //We have to recode the oldquestion field
-            $question = backup_getid($restore->backup_unique_code,"question",$version->oldquestion);
-            if ($question) {
-                $version->oldquestion = $question->new_id;
-            }
-
-            //We have to recode the newquestion field
-            $question = backup_getid($restore->backup_unique_code,"question",$version->newquestion);
-            if ($question) {
-                $version->newquestion = $question->new_id;
-            }
-
-            //We have to recode the userid field
-            $user = backup_getid($restore->backup_unique_code,"user",$version->userid);
-            if ($user) {
-                $version->userid = $user->new_id;
-            } else {  //Assign to current user
-                $version->userid = $USER->id;
-            }
-
-            //The structure is equal to the db, so insert the quiz_question_versions
-            $newid = $DB->insert_record ("quiz_question_versions",$version);
-
-            //Do some output
-            if (($i+1) % 10 == 0) {
-                if (!defined('RESTORE_SILENTLY')) {
-                    echo ".";
-                    if (($i+1) % 200 == 0) {
-                        echo "<br />";
-                    }
-                }
-                backup_flush(300);
-            }
-
-            if ($newid) {
-                //We have the newid, update backup_ids
-                backup_putid($restore->backup_unique_code,"quiz_question_versions",$oldid,
-                             $newid);
-            } else {
-                $status = false;
-            }
-        }
-
-        return $status;
-    }
-
     //This function restores the quiz_attempts
     function quiz_attempts_restore_pre15_mods($quiz_id,$info,$restore,$quizquestions) {
         global $CFG, $DB;
index 07f646d12437b63db8c344a139fc88ab57f37c16..a65c89176bd993b26fe08a950a0e351af7e33e0c 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2008072900;   // The (date) version of this module
+$module->version  = 2008081500;   // The (date) version of this module
 $module->requires = 2008072401;   // Requires this Moodle version
 $module->cron     = 0;            // How often should cron check this module (seconds)?