MDL-16058 - Remove obsolete quiz_question_versions table.

This commit is contained in:
tjhunt 2008-08-15 08:23:09 +00:00
parent 4f089b2155
commit 6b22437658
7 changed files with 32 additions and 248 deletions

View 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)
@ -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;

View File

@ -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"/>
@ -93,25 +93,7 @@
<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"/>

View 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;
}

View 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;
}

View File

@ -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 "<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;

View 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
@ -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 "<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;

View 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)?