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

68
mod/survey/db/migrate2utf8.php Executable file
View file

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

75
mod/survey/db/migrate2utf8.xml Executable file
View file

@ -0,0 +1,75 @@
<DBMIGRATION type="mod/survey" VERSION="2005120100">
<TABLES>
<TABLE name="survey_questions">
<FIELDS>
<FIELD name="options" method="NO_CONV" type="text" length="0" />
<FIELD name="shorttext" method="NO_CONV" type="varchar" length="30" />
</FIELDS>
</TABLE>
<TABLE name="survey_analysis">
<FIELDS>
<FIELD name="notes" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT sa.userid
FROM {$CFG->prefix}survey_analysis sa
WHERE sa.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT s.course
FROM {$CFG->prefix}survey s,
{$CFG->prefix}survey_analysis sa
WHERE s.id = sa.survey
AND sa.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="survey_answers">
<FIELDS>
<FIELD name="answerone" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT sa.userid
FROM {$CFG->prefix}survey_answers sa
WHERE sa.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT s.course
FROM {$CFG->prefix}survey s,
{$CFG->prefix}survey_answers sa
WHERE s.id = sa.survey
AND sa.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
<FIELD name="answertwo" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT sa.userid
FROM {$CFG->prefix}survey_answers sa
WHERE sa.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT s.course
FROM {$CFG->prefix}survey s,
{$CFG->prefix}survey_answers sa
WHERE s.id = sa.survey
AND sa.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="survey">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_survey_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="intro" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_survey_intro(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="questions" method="NO_CONV" type="varchar" length="255" />
</FIELDS>
</TABLE>
</TABLES>
</DBMIGRATION>