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

66
mod/chat/db/migrate2utf8.php Executable file
View file

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

36
mod/chat/db/migrate2utf8.xml Executable file
View file

@ -0,0 +1,36 @@
<DBMIGRATION type="mod/chat" VERSION="2005120100">
<TABLES>
<TABLE name="chat_messages">
<FIELDS>
<FIELD name="message" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT chm.userid
FROM {$CFG->prefix}chat_messages chm
WHERE chm.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT ch.course
FROM {$CFG->prefix}chat ch,
{$CFG->prefix}chat_messages chm
WHERE ch.id = chm.chatid
AND chm.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="chat">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<SQL_DETECT_COURSE>
migrate2utf8_chat_name(RECORDID)
</SQL_DETECT_COURSE>
</FIELD>
<FIELD name="intro" method="PHP_FUNCTION" type="text" length="0">
<SQL_DETECT_COURSE>
migrate2utf8_chat_intro(RECORDID)
</SQL_DETECT_COURSE>
</FIELD>
</FIELDS>
</TABLE>
</TABLES>
</DBMIGRATION>