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

67
mod/label/db/migrate2utf8.php Executable file
View file

@ -0,0 +1,67 @@
<?
function migrate2utf_label_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$label = get_record('label','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($label->course); //Non existing!
$userlang = get_main_teacher_lang($label->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($label->name, $fromenc);
$newlabel = new object;
$newlabel->id = $recordid;
$newlabel->name = $result;
update_record('label',$newlabel);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_label_content($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$label = get_record('label','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($label->course); //Non existing!
$userlang = get_main_teacher_lang($label->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($label->content, $fromenc);
$newlabel = new object;
$newlabel->id = $recordid;
$newlabel->content = $result;
update_record('label',$newlabel);
/// And finally, just return the converted field
return $result;
}
?>

18
mod/label/db/migrate2utf8.xml Executable file
View file

@ -0,0 +1,18 @@
<DBMIGRATION type="mod/label" VERSION="2005120100">
<TABLES>
<TABLE name="label">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_label_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="content" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_label_content(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
</TABLES>
</DBMIGRATION>