From: toyomoyo Date: Fri, 6 Oct 2006 08:26:37 +0000 (+0000) Subject: fix for MDL-6336 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=837bde0cc0ac3968bfbcdea3f6b060e7e50bd3a7;p=moodle.git fix for MDL-6336 --- diff --git a/mod/lesson/db/migrate2utf8.php b/mod/lesson/db/migrate2utf8.php index 338c556e5f..6a7dd3a8a6 100755 --- a/mod/lesson/db/migrate2utf8.php +++ b/mod/lesson/db/migrate2utf8.php @@ -1,4 +1,63 @@ prefix}lesson_attempts la + WHERE la.id=$recordid"); + + $course = get_record_sql("SELECT l.course + FROM {$CFG->prefix}lesson l, + {$CFG->prefix}lesson_attempts la + WHERE l.id = la.lessonid + AND la.id = $recordid"); + + if (!$lessonattempts = get_record('lesson_attempts','id',$recordid)) { + log_the_problem_somewhere(); + return false; + } + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = get_course_lang($course->course); + $userlang = get_user_lang($user->userid); + $fromencstudent = get_original_encoding($sitelang, $courselang, $userlang); // this is used for answer field + $userlang = get_main_teacher_lang($course->course); + $fromencteacher = get_original_encoding($sitelang, $courselang, $userlang); // this is used for response field + } + + $result = $lessonattempts->useranswer; // init to avoid warnings + // if unserialize success, meaning it is an object + if ($attempt = unserialize($lessonattempts->useranswer)) { + $attempt->answer = utfconvert($attempt->answer, $fromencstudent); + $attempt->response = utfconvert(attempt->response, $fromencteacher); + $newla = new object; + $newla->id = $recordid; + $newla->useranswer = serialize($attempt); // serialize it back + migrate2utf8_update_record('lesson_attempts', $newla); + + } else { // just a string + $result = utfconvert($lessonattempts->useranswer, $fromencstudent); + $newla = new object; + $newla->id = $recordid; + $newla->useranswer = $result;// serialize it back + migrate2utf8_update_record('lesson_attempts', $newla); + } + + return $result; +} + function migrate2utf8_lesson_answers_answer($recordid){ global $CFG, $globallang; diff --git a/mod/lesson/db/migrate2utf8.xml b/mod/lesson/db/migrate2utf8.xml index 0e4da1551e..e06d6f7aca 100755 --- a/mod/lesson/db/migrate2utf8.xml +++ b/mod/lesson/db/migrate2utf8.xml @@ -5,19 +5,10 @@
- - - SELECT la.userid - FROM {$CFG->prefix}lesson_attempts la - WHERE la.id=RECORDID - - - SELECT l.course - FROM {$CFG->prefix}lesson l, - {$CFG->prefix}lesson_attempts la - WHERE l.id = la.lessonid - AND la.id = RECORDID - + + + migrate2utf8_lesson_attempts_useranswer(RECORDID) +