From: tjhunt Date: Wed, 28 Jun 2006 17:21:53 +0000 (+0000) Subject: Bug #5918 - essay question comments from teachers lost in 1.6 upgrade. Thanks to... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=04a4cd2a0e554aeb901db0d486c5dda83f629b9d;p=moodle.git Bug #5918 - essay question comments from teachers lost in 1.6 upgrade. Thanks to Mark Nielsen the suggestion of how to fix. Merged from MOODLE_16_STABLE. --- diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index fd4bb0b88e..2f39b73604 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -1056,8 +1056,44 @@ function quiz_upgrade($oldversion) { } if ($oldversion < 2006060700) { // fix for 5720 - execute_sql('DROP TABLE '.$CFG->prefix.'question_essay_states', false); - execute_sql('DROP TABLE '.$CFG->prefix.'question_essay', false); + + // Copy the teacher comments from the question_essay_states table to the new + // question_sessions table. + + // Get the attempt unique ID, teacher comment, graded flag, state ID, and question ID + // based on the quesiont_essay_states + if ($results = get_records_sql("SELECT a.uniqueid, es.response AS essaycomment, es.graded AS isgraded, + qs.id AS stateid, qs.question AS questionid + FROM {$CFG->prefix}question_states as qs, + {$CFG->prefix}question_essay_states es, + {$CFG->prefix}quiz_attempts a + WHERE es.stateid = qs.id AND a.uniqueid = qs.attempt")) { + foreach ($results as $result) { + // Create a state object to be used for updating + $state = new stdClass; + $state->id = $result->stateid; + + if ($result->isgraded) { + // Graded - save comment to the sessions and change state event to QUESTION_EVENTMANUALGRADE + if (!set_field('question_sessions', 'comment', $result->essaycomment, 'attemptid', $result->uniqueid, 'questionid', $result->questionid)) { + notify("Essay Table Migration: Cannot save comment"); + } + $state->event = 9; //QUESTION_EVENTMANUALGRADE; + } else { + // Not graded + $state->event = 7; //QUESTION_EVENTSUBMIT; + } + + // Save the event + if (!update_record('question_states', $state)) { + notify("Essay Table Migration: Cannot update state"); + } + } + } + + // dropping unused tables + execute_sql('DROP TABLE '.$CFG->prefix.'question_essay_states'); + execute_sql('DROP TABLE '.$CFG->prefix.'question_essay'); execute_sql('DROP TABLE '.$CFG->prefix.'quiz_attemptonlast_datasets', false); } diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index 8a4a6fc4bb..331b21eabf 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -1240,8 +1240,43 @@ function quiz_upgrade($oldversion) { $record = get_record_sql("SELECT nextval('{$CFG->prefix}quiz_attempts_id_seq')"); set_config('attemptuniqueid', empty($record->nextid) ? 1 : $record->nextid); // the above will be a race condition, see bug 5468 + modify_database('','CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);'); + // Copy the teacher comments from the question_essay_states table to the new + // question_sessions table. + + // Get the attempt unique ID, teacher comment, graded flag, state ID, and question ID + // based on the quesiont_essay_states + if ($results = get_records_sql("SELECT a.uniqueid, es.response AS essaycomment, es.graded AS isgraded, + qs.id AS stateid, qs.question AS questionid + FROM {$CFG->prefix}question_states as qs, + {$CFG->prefix}question_essay_states es, + {$CFG->prefix}quiz_attempts a + WHERE es.stateid = qs.id AND a.uniqueid = qs.attempt")) { + foreach ($results as $result) { + // Create a state object to be used for updating + $state = new stdClass; + $state->id = $result->stateid; + + if ($result->isgraded) { + // Graded - save comment to the sessions and change state event to QUESTION_EVENTMANUALGRADE + if (!set_field('question_sessions', 'comment', $result->essaycomment, 'attemptid', $result->uniqueid, 'questionid', $result->questionid)) { + notify("Essay Table Migration: Cannot save comment"); + } + $state->event = 9; //QUESTION_EVENTMANUALGRADE; + } else { + // Not graded + $state->event = 7; //QUESTION_EVENTSUBMIT; + } + + // Save the event + if (!update_record('question_states', $state)) { + notify("Essay Table Migration: Cannot update state"); + } + } + } + // dropping unused tables execute_sql('DROP TABLE '.$CFG->prefix.'question_essay_states'); execute_sql('DROP TABLE '.$CFG->prefix.'question_essay'); @@ -1384,6 +1419,7 @@ function quiz_upgrade($oldversion) { } + return true; }