utf8 migration support scripts

This commit is contained in:
toyomoyo 2006-01-09 06:06:49 +00:00
parent bbbb201364
commit 1e4d9ff6dc
36 changed files with 4767 additions and 0 deletions

502
mod/quiz/db/migrate2utf8.php Executable file
View file

@ -0,0 +1,502 @@
<?
function migrate2utf8_quiz_questions_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions 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('quiz_questions','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quizquestions->name, $fromenc);
$newquizquestion = new object;
$newquizquestion->id = $recordid;
$newquizquestion->name = $result;
update_record('quiz_question',$newquizquestion);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_questions_questiontext($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions 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('quiz_questions','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quizquestions->questiontext, $fromenc);
$newquizquestion = new object;
$newquizquestion->id = $recordid;
$newquizquestion->questiontext = $result;
update_record('quiz_question',$newquizquestion);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_numerical_units_unit($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}quiz_numerical_units qnu
WHERE qc.id = qq.category
AND qq.id = qnu.question
AND qnu.id = $recordid";
if (!$quiz = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$quiznumericalunits = get_record('quiz_numerical_units','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quiznumericalunits->unit, $fromenc);
$newquiznumericalunits = new object;
$newquiznumericalunits->id = $recordid;
$newquiznumericalunits->unit = $result;
update_record('quiz_numerical_units',$newquiznumericalunits);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_match_sub_questiontext($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}quiz_match_sub qms
WHERE qc.id = qq.category
AND qq.id = qms.question
AND qms.id = $recordid";
if (!$quiz = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$quizmatchsub = get_record('quiz_match_sub','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quizmatchsub->questiontext, $fromenc);
$newquizmatchsub = new object;
$newquizmatchsub->id = $recordid;
$newquizmatchsub->questiontext = $result;
update_record('quiz_numerical_units',$newquizmatchsub);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_match_sub_answertext($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}quiz_match_sub qms
WHERE qc.id = qq.category
AND qq.id = qms.question
AND qms.id = $recordid";
if (!$quiz = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$quizmatchsub = get_record('quiz_match_sub','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quizmatchsub->answertext, $fromenc);
$newquizmatchsub = new object;
$newquizmatchsub->id = $recordid;
$newquizmatchsub->answertext = $result;
update_record('quiz_numerical_units',$newquizmatchsub);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_answer_answer($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}quiz_answer qa
WHERE qc.id = qq.category
AND qq.id = qa.question
AND qa.id = $recordid";
if (!$quiz = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$quizanswer= get_record('quiz_answer','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quizanswer->answer, $fromenc);
$newquizanswer = new object;
$newquizanswer->id = $recordid;
$newquizanswer->answer = $result;
update_record('quiz_answer',$newquizanswer);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_dataset_definitions_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_dataset_definitions qdd
WHERE qc.id = qdd.category
AND qdd.id = $recordid";
if (!$quiz = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$quizdatasetdefinition = get_record('quiz_answer','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quizdatasetdefinition->name, $fromenc);
$newquizdatasetdefinition = new object;
$newquizdatasetdefinition->id = $recordid;
$newquizdatasetdefinition->name = $result;
update_record('quiz_dataset_definition',$newquizdatasetdefinition);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_categories_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
WHERE qc.id = $recordid";
if (!$quiz = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$quizcategory = get_record('quiz_categories','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quizcategory->name, $fromenc);
$newquizcategory = new object;
$newquizcategory->id = $recordid;
$newquizcategory->name = $result;
update_record('quiz_category',$newquizcategory);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_categories_info($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
WHERE qc.id = $recordid";
if (!$quiz = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$quizcategory = get_record('quiz_categories','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quizcategory->info, $fromenc);
$newquizcategory = new object;
$newquizcategory->id = $recordid;
$newquizcategory->info = $result;
update_record('quiz_category',$newquizcategory);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$quiz = get_record('quiz','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quiz->name, $fromenc);
$newquiz = new object;
$newquiz->id = $recordid;
$newquiz->name = $result;
update_record('quiz',$newquiz);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_intro($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$quiz = get_record('quiz','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quiz->intro, $fromenc);
$newquiz = new object;
$newquiz->id = $recordid;
$newquiz->intro = $result;
update_record('quiz',$newquiz);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_password($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$quiz = get_record('quiz','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$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
$textlib = textlib_get_instance();
/// Convert the text
$result = $textlib->convert($quiz->password, $fromenc);
$newquiz = new object;
$newquiz->id = $recordid;
$newquiz->password = $result;
update_record('quiz',$newquiz);
/// And finally, just return the converted field
return $result;
}
?>

208
mod/quiz/db/migrate2utf8.xml Executable file
View file

@ -0,0 +1,208 @@
<DBMIGRATION type="mod/quiz" VERSION="2005120100">
<TABLES>
<TABLE name="quiz_shortanswer">
<FIELDS>
<FIELD name="answers" method="NO_CONV" type="text" length="0" />
</FIELDS>
</TABLE>
<TABLE name="quiz_numerical">
<FIELDS>
<FIELD name="tolerance" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz_newest_states">
<FIELDS>
<FIELD name="sumpenalty" method="NO_CONV" type="varchar" length="10" />
</FIELDS>
</TABLE>
<TABLE name="quiz_multichoice">
<FIELDS>
<FIELD name="answers" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz_multianswers">
<FIELDS>
<FIELD name="answers" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz_match">
<FIELDS>
<FIELD name="subquestions" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz_essay">
<FIELDS>
<FIELD name="answer" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz_dataset_items">
<FIELDS>
<FIELD name="value" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz_calculated">
<FIELDS>
<FIELD name="tolerance" method="NO_CONV" type="varchar" length="20" />
</FIELDS>
</TABLE>
<TABLE name="quiz_attempts">
<FIELDS>
<FIELD name="sumgrades" method="NO_CONV" type="varchar" length="10" />
<FIELD name="layout" method="NO_CONV" type="text" length="0" />
</FIELDS>
</TABLE>
<TABLE name="quiz_states">
<FIELDS>
<FIELD name="answer" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT qa.userid
FROM {$CFG->prefix}quiz_states qs,
{$CFG->prefix}quiz_attempts qa
WHERE qa.id = qs.attempt
AND qs.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT q.course
FROM {$CFG->prefix}quiz q,
{$CFG->prefix}quiz_states qs,
{$CFG->prefix}quiz_attempts qa
WHERE q.id = qa.quiz
AND qa.id = qs.attempt
AND qs.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
<FIELD name="grade" method="NO_CONV" type="varchar" length="10" />
<FIELD name="raw_grade" method="NO_CONV" type="varchar" length="10" />
<FIELD name="penalty" method="NO_CONV" type="varchar" length="10" />
</FIELDS>
</TABLE>
<TABLE name="quiz_questions">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_quiz_questions_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="questiontext" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_quiz_questions_questiontext(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="image" method="NO_CONV" type="varchar" length="255" />
<FIELD name="stamp" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz_numerical_units">
<FIELDS>
<FIELD name="unit" method="PHP_FUNCTION" type="varchar" length="50">
<PHP_FUNCTION>
migrate2utf8_quiz_numerical_units_unit(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="quiz_match_sub">
<FIELDS>
<FIELD name="questiontext" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf_quiz_match_sub_questionext(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="answertext" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf_quiz_match_sub_answertext(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="quiz_answer">
<FIELDS>
<FIELD name="answer" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_quiz_answer_answer(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="fraction" method="NO_CONV" type="varchar" length="10" />
<FIELD name="feedback" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_quiz_answer_feedback(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="quiz_dataset_definitions">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_quiz_dataset_definitions_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="options" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz_essay_states">
<FIELDS>
<FIELD name="fraction" method="NO_CONV" type="varchar" length="10" />
<FIELD name="response" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT qa.userid
FROM {$CFG->prefix}quiz_states qs,
{$CFG->prefix}quiz_attempts qa,
{$CFG->prefix}quiz_essay_states qes
WHERE qa.id = qs.attempt
AND qs.id = qes.stateid
AND qes.id = RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT q.course
FROM {$CFG->prefix}quiz q,
{$CFG->prefix}quiz_attempts qa,
{$CFG->prefix}quiz_states qs,
{$CFG->prefix}quiz_essay_states qes
WHERE q.id = qa.quiz
AND qa.id = qs.attempt
AND qs.id = qes.stateid
AND qes.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
<FIELD name="options" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz_categories">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_quiz_categories_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="info" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_quiz_categories_info(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="stamp" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
<TABLE name="quiz">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_quiz_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="intro" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_quiz_intro(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="questions" method="NO_CONV" type="varchar" length="255" />
<FIELD name="password" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_quiz_password(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="subnet" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
</TABLES>
</DBMIGRATION>