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

221
mod/lesson/db/migrate2utf8.php Executable file
View file

@ -0,0 +1,221 @@
<?
function migrate2utf8_lesson_answers_answer($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT l.course
FROM {$CFG->prefix}lesson l,
{$CFG->prefix}lesson_answers la
WHERE l.id = la.lessonid
AND la.id = $recordid";
if (!$lessonanswers = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$lesson = get_record('lesson','id',$lessonanswers->course)) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($lessonanswers->course); //Non existing!
$userlang = get_main_teacher_lang($lessonanswers->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($lessonanswers->answer, $fromenc);
$newlessonanswers = new object;
$newlessonanswers->id = $recordid;
$newlessonanswers->answer = $result;
update_record('lesson_answers',$newlessonanswers);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_lesson_answers_response($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT l.course
FROM {$CFG->prefix}lesson l,
{$CFG->prefix}lesson_answers la
WHERE l.id = la.lessonid
AND la.id = $recordid";
if (!$lessonanswers = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$lesson = get_record('lesson','id',$lessonanswers->course)) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($lessonanswers->course); //Non existing!
$userlang = get_main_teacher_lang($lessonanswers->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($lessonanswers->response, $fromenc);
$newlessonanswers = new object;
$newlessonanswers->id = $recordid;
$newlessonanswers->response = $result;
update_record('lesson_answers',$newlessonanswers);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_lesson_default_password($recordid){
///um
}
function migrate2utf8_lesson_pages_contents($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT l.course
FROM {$CFG->prefix}lesson l,
{$CFG->prefix}lesson_pages lp
WHERE l.id = lp.lessonid
AND lp.id = $recordid";
if (!$lessonpages = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$lesson = get_record('lesson','id',$lessonpages->course)) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($lessonpages->course); //Non existing!
$userlang = get_main_teacher_lang($lessonpages->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($lessonpages->contents, $fromenc);
$newlessonpages = new object;
$newlessonpages->id = $recordid;
$newlessonpages->contents = $result;
update_record('lesson_answers',$newlessonpages);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_lesson_pages_title($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT l.course
FROM {$CFG->prefix}lesson l,
{$CFG->prefix}lesson_pages lp
WHERE l.id = lp.lessonid
AND lp.id = $recordid";
if (!$lessonpages = get_record_sql($SQL)) {
log_the_problem_somewhere();
return false;
}
if (!$lesson = get_record('lesson','id',$lessonpages->course)) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($lessonpages->course); //Non existing!
$userlang = get_main_teacher_lang($lessonpages->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($lessonpages->title, $fromenc);
$newlessonpages = new object;
$newlessonpages->id = $recordid;
$newlessonpages->title = $result;
update_record('lesson_answers',$newlessonpages);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_lesson_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$lesson = get_record('lesson','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($lesson->course); //Non existing!
$userlang = get_main_teacher_lang($lesson->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($lesson->name, $fromenc);
$newlesson = new object;
$newlesson->id = $recordid;
$newlesson->name = $result;
update_record('lesson',$newlesson);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_lesson_password($recordid){
///um
}
?>

80
mod/lesson/db/migrate2utf8.xml Executable file
View file

@ -0,0 +1,80 @@
<DBMIGRATION type="mod/lesson" VERSION="2005120100">
<TABLES>
<TABLE name="lesson_attempt">
<FIELDS>
<FIELD name="useranswer" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT la.userid
FROM {$CFG->prefix}lesson_attempt la
WHERE la.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT l.course
FROM {$CFG->prefix}lesson l,
{$CFG->prefix}lesson_attempt la
WHERE l.id = la.lessonid
AND la.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="lesson_high_scores">
<FIELDS>
<FIELD name="nickname" method="NO_CONV" type="varchar" length="5" />
</FIELDS>
</TABLE>
<TABLE name="lesson_answers">
<FIELDS>
<FIELD name="answer" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_lesson_answers_answer(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="response" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_lesson_answers_answer(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="lesson_default">
<FIELDS>
<FIELD name="password" method="PHP_FUNCTION" type="varchar" length="32">
<PHP_FUNCTION>
migrate2utf8_lesson_default_password(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="bgcolor" method="NO_CONV" type="varchar" length="7" />
</FIELDS>
</TABLE>
<TABLE name="lesson_pages">
<FIELDS>
<FIELD name="title" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_lesson_pages_title(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="contents" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_lesson_pages_content(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="lesson">
<FIELDS>
<FIELD name="name" method="PLAIN_SQL_UPDATE" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_lesson_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="password" method="PHP_FUNCTION" type="varchar" length="32">
<PHP_FUNCTION>
migrate2utf8_lesson_password(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="bgcolor" method="NO_CONV" type="varchar" length="7" />
</FIELDS>
</TABLE>
</TABLES>
</DBMIGRATION>