From: toyomoyo Date: Wed, 30 Aug 2006 06:12:12 +0000 (+0000) Subject: utf8 migrate support for additional fields MDL-6339 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=247cdeb68f4590786578f8d5e210737c0eec6d86;p=moodle.git utf8 migrate support for additional fields MDL-6339 --- diff --git a/mod/quiz/db/migrate2utf8.php b/mod/quiz/db/migrate2utf8.php index 40772d2135..282b05bc2a 100755 --- a/mod/quiz/db/migrate2utf8.php +++ b/mod/quiz/db/migrate2utf8.php @@ -1,5 +1,161 @@ prefix}question_categories qc, + {$CFG->prefix}question qq, + {$CFG->prefix}question_multichoice qm + WHERE qc.id = qq.category + AND qq.id = qm.question + AND qm.id = $recordid"; + + if (!$quiz = get_record_sql($SQL)) { + log_the_problem_somewhere(); + return false; + } + + if (!$questionmultichoice = get_record('question_multichoice','id',$recordid)) { + log_the_problem_somewhere(); + return false; + } + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = get_course_lang($quiz->course); //Non existing! + $userlang = get_main_teacher_lang($quiz->course); //N.E.!! + + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// We are going to use textlib facilities + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($questionmultichoice->correctfeedback, $fromenc); + + $newquestionmultichoice = new object; + $newquestionmultichoice->id = $recordid; + $newquestionmultichoice->correctfeedback = $result; + update_record('question_multichoice',$newquestionmultichoice); + } +/// And finally, just return the converted field + return $result; +} + +function migrate2utf8_question_multichoice_partiallycorrectfeedback($recordid){ + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + $SQL = "SELECT qc.course + FROM {$CFG->prefix}question_categories qc, + {$CFG->prefix}question qq, + {$CFG->prefix}question_multichoice qm + WHERE qc.id = qq.category + AND qq.id = qm.question + AND qm.id = $recordid"; + + if (!$quiz = get_record_sql($SQL)) { + log_the_problem_somewhere(); + return false; + } + + if (!$questionmultichoice = get_record('question_multichoice','id',$recordid)) { + log_the_problem_somewhere(); + return false; + } + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = get_course_lang($quiz->course); //Non existing! + $userlang = get_main_teacher_lang($quiz->course); //N.E.!! + + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// We are going to use textlib facilities + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($questionmultichoice->partiallycorrectfeedback, $fromenc); + + $newquestionmultichoice = new object; + $newquestionmultichoice->id = $recordid; + $newquestionmultichoice->partiallycorrectfeedback= $result; + update_record('question_multichoice',$newquestionmultichoice); + } +/// And finally, just return the converted field + return $result; +} + +function migrate2utf8_question_multichoice_incorrectfeedback($recordid){ + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + $SQL = "SELECT qc.course + FROM {$CFG->prefix}question_categories qc, + {$CFG->prefix}question qq, + {$CFG->prefix}question_multichoice qm + WHERE qc.id = qq.category + AND qq.id = qm.question + AND qm.id = $recordid"; + + if (!$quiz = get_record_sql($SQL)) { + log_the_problem_somewhere(); + return false; + } + + if (!$questionmultichoice = get_record('question_multichoice','id',$recordid)) { + log_the_problem_somewhere(); + return false; + } + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = get_course_lang($quiz->course); //Non existing! + $userlang = get_main_teacher_lang($quiz->course); //N.E.!! + + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// We are going to use textlib facilities + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($questionmultichoice->incorrectfeedback, $fromenc); + + $newquestionmultichoice = new object; + $newquestionmultichoice->id = $recordid; + $newquestionmultichoice->incorrectfeedback= $result; + update_record('question_multichoice',$newquestionmultichoice); + } +/// And finally, just return the converted field + return $result; +} + function migrate2utf8_quiz_feedback_feedbacktext($recordid) { global $CFG, $globallang; /// Some trivial checks @@ -198,6 +354,55 @@ function migrate2utf8_question_questiontext($recordid){ return $result; } +function migrate2utf8_question_commentarytext($recordid){ + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + $SQL = "SELECT qc.course + FROM {$CFG->prefix}question_categories qc, + {$CFG->prefix}question qq + WHERE qc.id = qq.category + AND qq.id = $recordid"; + + if (!$quiz = get_record_sql($SQL)) { + log_the_problem_somewhere(); + return false; + } + + if (!$quizquestions = get_record('question','id',$recordid)) { + log_the_problem_somewhere(); + return false; + } + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = get_course_lang($quiz->course); //Non existing! + $userlang = get_main_teacher_lang($quiz->course); //N.E.!! + + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// We are going to use textlib facilities + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($quizquestions->commentarytext, $fromenc); + + $newquizquestion = new object; + $newquizquestion->id = $recordid; + $newquizquestion->commentarytext = $result; + update_record('question',$newquizquestion); + } +/// And finally, just return the converted field + return $result; +} function migrate2utf8_question_numerical_units_unit($recordid){ global $CFG, $globallang; diff --git a/mod/quiz/db/migrate2utf8.xml b/mod/quiz/db/migrate2utf8.xml index 4e672aa095..50a704764d 100755 --- a/mod/quiz/db/migrate2utf8.xml +++ b/mod/quiz/db/migrate2utf8.xml @@ -77,6 +77,21 @@ + + + migrate2utf8_question_multichoice_correctfeedback(RECORDID) + + + + + migrate2utf8_question_multichoice_partiallycorrectfeedback(RECORDID) + + + + + migrate2utf8_question_multichoice_incorrectfeedback(RECORDID) + +
@@ -145,6 +160,11 @@ + + + migrate2utf8_question_commentarytext(RECORDID) + +