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

186
mod/hotpot/db/migrate2utf8.php Executable file
View file

@ -0,0 +1,186 @@
<?
function migrate2utf_hotpot_questions_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT h.course
FROM {$CFG->prefix}hotpot h,
{$CFG->prefix}hotpot_questions hq
WHERE h.id = hq.hotpot
AND hq.id = $recordid";
if (!$hotpot = get_record_sql($SQL) {
log_the_problem_somewhere();
return false;
}
if (!$hotpotquestion = get_record_sql('hotpot_questions','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($hotpot->course); //Non existing!
$userlang = get_main_teacher_lang($hotpot->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($hotpotquestion->name, $fromenc);
$newhotpotquestion = new object;
$newhotpotquestion->id = $recordid;
$newhotpotquestion->name = $result;
update_record('forum',$newhotpotquestion);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_hotpot_questions_text($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT h.course
FROM {$CFG->prefix}hotpot h,
{$CFG->prefix}hotpot_questions hq
WHERE h.id = hq.hotpot
AND hq.id = $recordid";
if (!$hotpot = get_record_sql($SQL) {
log_the_problem_somewhere();
return false;
}
if (!$hotpotquestion = get_record_sql('hotpot_questions','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($hotpot->course); //Non existing!
$userlang = get_main_teacher_lang($hotpot->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($hotpotquestion->text, $fromenc);
$newhotpotquestion = new object;
$newhotpotquestion->id = $recordid;
$newhotpotquestion->text = $result;
update_record('forum',$newhotpotquestion);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_hotpot_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$hotpot = get_record('hotpot','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($hotpot->course); //Non existing!
$userlang = get_main_teacher_lang($hotpot->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($hotpot->name, $fromenc);
$newhotpot = new object;
$newhotpot->id = $recordid;
$newhotpot->name = $result;
update_record('hotpot',$newhotpot);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_glossary_summary($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$hotpot = get_record('hotpot','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($hotpot->course); //Non existing!
$userlang = get_main_teacher_lang($hotpot->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($hotpot->summary, $fromenc);
$newglossary = new object;
$newglossary->id = $recordid;
$newglossary->summary = $result;
update_record('hotpot',$newhotpot);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_glossary_password($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$hotpot = get_record('hotpot','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($hotpot->course); //Non existing!
$userlang = get_main_teacher_lang($hotpot->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($hotpot->password, $fromenc);
$newglossary = new object;
$newglossary->id = $recordid;
$newglossary->password = $result;
update_record('hotpot',$newhotpot);
/// And finally, just return the converted field
return $result;
}
?>

61
mod/hotpot/db/migrate2utf8.xml Executable file
View file

@ -0,0 +1,61 @@
<DBMIGRATION type="mod/hotpot" VERSION="2005120100">
<TABLES>
<TABLE name="hotpot_details">
<FIELDS>
<FIELD name="details" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
</SQL_DETECT_USER>
SELECT ha.userid
FROM {$CFG->prefix}hotpot_attempts ha,
{$CFG->prefix}hotpot_details hd
WHERE AND ha.id = hd.attempt
AND hd.id = RECORDID
<SQL_DETECT_COURSE>
SELECT h.course
FROM {$CFG->prefix}hotpot h,
{$CFG->prefix}hotpot_attempts ha,
{$CFG->prefix}hotpot_details hd
WHERE h.id = ha.hotpot
AND ha.id = hd.attempt
AND hd.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="hotpot_questions">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_hotpot_questions_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="text" method="PLAIN_SQL_UPDATE" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_hotpot_questions_text(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="hotpot">
<FIELDS>
<FIELD name="name" method="PLAIN_SQL_UPDATE" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_hotpot_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="reference" method="NO_CONV" type="varchar" length="255" />
<FIELD name="summary" method="PLAIN_SQL_UPDATE" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_hotpot_summary(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="password" method="PLAIN_SQL_UPDATE" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_hotpot_password(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="subnet" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
</TABLES>
</DBMIGRATION>