fix for MDL-6336

This commit is contained in:
toyomoyo
2006-10-06 08:26:37 +00:00
parent a81468432a
commit 837bde0cc0
2 changed files with 63 additions and 13 deletions
+59
View File
@@ -1,4 +1,63 @@
<?php // $Id$
// fix for MDL-6336
// handling serialized object
function migrate2utf8_lesson_attempts_useranswer($recordid) {
global $CFG, $globallang;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$user = get_record_sql("SELECT la.userid
FROM {$CFG->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;
+4 -13
View File
@@ -5,19 +5,10 @@
<TABLE name="lesson_timer" />
<TABLE name="lesson_attempts">
<FIELDS>
<FIELD name="useranswer" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT la.userid
FROM {$CFG->prefix}lesson_attempts la
WHERE la.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT l.course
FROM {$CFG->prefix}lesson l,
{$CFG->prefix}lesson_attempts la
WHERE l.id = la.lessonid
AND la.id = RECORDID
</SQL_DETECT_COURSE>
<FIELD name="useranswer" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_lesson_attempts_useranswer(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>