From 6b22437658e25b609fa9e70e992caf6b4f28baf6 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 15 Aug 2008 08:23:09 +0000 Subject: [PATCH] MDL-16058 - Remove obsolete quiz_question_versions table. --- mod/quiz/backuplib.php | 39 ++------------- mod/quiz/db/install.xml | 22 +-------- mod/quiz/db/upgrade.php | 11 +++++ mod/quiz/lib.php | 17 +------ mod/quiz/restorelib.php | 94 ++--------------------------------- mod/quiz/restorelibpre15.php | 95 ++++-------------------------------- mod/quiz/version.php | 2 +- 7 files changed, 32 insertions(+), 248 deletions(-) diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index 21a11d7081..230777c38c 100644 --- a/mod/quiz/backuplib.php +++ b/mod/quiz/backuplib.php @@ -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) @@ -279,8 +279,6 @@ $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 @@ -377,37 +375,6 @@ 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; diff --git a/mod/quiz/db/install.xml b/mod/quiz/db/install.xml index e9e6ad60ad..f0f997fc88 100755 --- a/mod/quiz/db/install.xml +++ b/mod/quiz/db/install.xml @@ -80,7 +80,7 @@ - +
@@ -93,25 +93,7 @@
- - - - - - - - - - - - - - - - - -
- +
diff --git a/mod/quiz/db/upgrade.php b/mod/quiz/db/upgrade.php index bb3b6ff6d1..8bb8473650 100644 --- a/mod/quiz/db/upgrade.php +++ b/mod/quiz/db/upgrade.php @@ -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; } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 2b0d456ccd..df5ce08c76 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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; } diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php index f5ed71eb87..d84bedf35a 100644 --- a/mod/quiz/restorelib.php +++ b/mod/quiz/restorelib.php @@ -13,10 +13,10 @@ // 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) @@ -109,8 +109,6 @@ $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 @@ -239,90 +237,6 @@ 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 "
"; - } - } - 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; diff --git a/mod/quiz/restorelibpre15.php b/mod/quiz/restorelibpre15.php index fcb5a6ff5f..c267f43f0f 100644 --- a/mod/quiz/restorelibpre15.php +++ b/mod/quiz/restorelibpre15.php @@ -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 @@ -1288,8 +1287,6 @@ $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 @@ -1365,78 +1362,6 @@ 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 "
"; - } - } - 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; diff --git a/mod/quiz/version.php b/mod/quiz/version.php index 07f646d124..a65c89176b 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -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)? -- 2.39.5