]> git.mjollnir.org Git - moodle.git/commitdiff
Bug #5918 - essay question comments from teachers lost in 1.6 upgrade. Thanks to...
authortjhunt <tjhunt>
Wed, 28 Jun 2006 17:21:53 +0000 (17:21 +0000)
committertjhunt <tjhunt>
Wed, 28 Jun 2006 17:21:53 +0000 (17:21 +0000)
mod/quiz/db/mysql.php
mod/quiz/db/postgres7.php

index fd4bb0b88ee427b9a7b80173750a8daeb3ce432c..2f39b7360440d392caf8605a58f5840827497f3e 100644 (file)
@@ -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);
     }
 
index 8a4a6fc4bb413e87b50103f9598273a1cab2527c..331b21eabf25d5de81ba5a2849f83547855102f4 100644 (file)
@@ -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;
 }