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

247
mod/workshop/db/migrate2utf8.php Executable file
View file

@ -0,0 +1,247 @@
<?
function migrate2utf_workshop_stockcomments_comments($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT w.course
FROM {$CFG->prefix}workshop w,
{$CFG->prefix}workshop_stockcomments ws
WHERE w.id = ws.workshopid
AND ws.id = $recordid";
if (!$workshop = get_record_sql($SQL) {
log_the_problem_somewhere();
return false;
}
if (!$workshopstockcomments = get_record('workshop_stockcomments','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($workshop->course); //Non existing!
$userlang = get_main_teacher_lang($workshop->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($workshopstockcomments->comment, $fromenc);
$newworkshopstockcomments = new object;
$newworkshopstockcomments->id = $recordid;
$newworkshopstockcomments->comment = $result;
update_record('workshop_stockcomments',$newworkshopstockcomments);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_workshop_rubrics_description($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT w.course
FROM {$CFG->prefix}workshop w,
{$CFG->prefix}workshop_stockcomments ws
WHERE w.id = ws.workshopid
AND ws.id = $recordid";
if (!$workshop = get_record_sql($SQL) {
log_the_problem_somewhere();
return false;
}
if (!$workshoprubrics = get_record('workshop_stockcomments','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($workshop->course); //Non existing!
$userlang = get_main_teacher_lang($workshop->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($workshoprubrics->description, $fromenc);
$newworkshoprubrics = new object;
$newworkshoprubrics->id = $recordid;
$newworkshoprubrics->description = $result;
update_record('workshop_rubricss',$newworkshoprubrics);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_workshop_grades_feedback($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT w.course
FROM {$CFG->prefix}workshop w,
{$CFG->prefix}workshop_grades wg
WHERE w.id = wg.workshopid
AND wg.id = $recordid";
if (!$workshop = get_record_sql($SQL) {
log_the_problem_somewhere();
return false;
}
if (!$workshopgrades = get_record('workshop_grades','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($workshop->course); //Non existing!
$userlang = get_main_teacher_lang($workshop->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($workshopgrades->feedback, $fromenc);
$newworkshopgrades = new object;
$newworkshopgrades->id = $recordid;
$newworkshopgrades->feedback = $result;
update_record('workshop_grades',$newworkshopgrades);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_workshop_elements_description($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
$SQL = "SELECT w.course
FROM {$CFG->prefix}workshop w,
{$CFG->prefix}workshop_elements we
WHERE w.id = we.workshopid
AND we.id = $recordid";
if (!$workshop = get_record_sql($SQL) {
log_the_problem_somewhere();
return false;
}
if (!$workshopelements = get_record('workshop_elements','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($workshop->course); //Non existing!
$userlang = get_main_teacher_lang($workshop->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($workshopelements->description, $fromenc);
$newworkshopelements = new object;
$newworkshopelements->id = $recordid;
$newworkshopelements->description = $result;
update_record('workshop_elements',$newworkshopelements);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_workshop_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$workshop = get_record('workshop','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($workshop->course); //Non existing!
$userlang = get_main_teacher_lang($workshop->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($workshop->name, $fromenc);
$newworkshop = new object;
$newworkshop->id = $recordid;
$newworkshop->name = $result;
update_record('workshop',$newworkshop);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_workshop_description($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$workshop = get_record('workshop','id',$recordid) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($workshop->course); //Non existing!
$userlang = get_main_teacher_lang($workshop->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($workshop->description, $fromenc);
$newworkshop = new object;
$newworkshop->id = $recordid;
$newworkshop->description = $result;
update_record('workshop',$newworkshop);
/// And finally, just return the converted field
return $result;
}
function migrate2utf_workshop_password($recordid){
global $CFG;
}
?>

142
mod/workshop/db/migrate2utf8.xml Executable file
View file

@ -0,0 +1,142 @@
<DBMIGRATION type="mod/workshop" VERSION="2005120100">
<TABLES>
<TABLE name="workshop_submissions">
<FIELDS>
<FIELD name="title" method="PLAIN_SQL_UPDATE" type="varchar" length="100">
<SQL_DETECT_USER>
SELECT ws.userid
FROM {$CFG->prefix}workshop_submissions ws
WHERE ws.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT w.course
FROM {$CFG->prefix}workshop w,
{$CFG->prefix}workshop_submissions ws
WHERE w.id = ws.workshopid
AND ws.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
<FIELD name="description" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT ws.userid
FROM {$CFG->prefix}workshop_submissions ws
WHERE ws.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT w.course
FROM {$CFG->prefix}workshop w,
{$CFG->prefix}workshop_submissions ws
WHERE w.id = ws.workshopid
AND ws.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="workshop_stockcomments">
<FIELDS>
<FIELD name="comments" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_workshop_stockcomments_comments(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="workshop_rubrics">
<FIELDS>
<FIELD name="description" method="PHP_FUNCTION" type="text" length="0">
<SQL_DETECT_COURSE>
<PHP_FUNCTION>
migrate2utf8_workshop_rubrics_description(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="workshop_grades">
<FIELDS>
<FIELD name="feedback" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_workshop_grades_feedback(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="workshop_elements">
<FIELDS>
<FIELD name="description" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_workshop_elements_description(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="workshop_comments">
<FIELDS>
<FIELD name="comments" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT wc.userid
FROM {$CFG->prefix}workshop_comments wc
WHERE wc.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT w.course
FROM {$CFG->prefix}workshop w,
{$CFG->prefix}workshop_comments wc
WHERE w.id = wc.workshopid
AND wc.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="workshop_assessments">
<FIELDS>
<FIELD name="generalcomment" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT ws.userid
FROM {$CFG->prefix}workshop_assessments wa
WHERE wa.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT w.course
FROM {$CFG->prefix}workshop w,
{$CFG->prefix}workshop_assessments wa
WHERE w.id = wa.workshopid
AND wa.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
<FIELD name="teachercomment" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT ws.userid
FROM {$CFG->prefix}workshop_assessments wa
WHERE wa.id=RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT w.course
FROM {$CFG->prefix}workshop w,
{$CFG->prefix}workshop_assessments wa
WHERE w.id = wa.workshopid
AND wa.id = RECORDID
</SQL_DETECT_COURSE>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="workshop">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_workshop_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="description" method="PLAIN_SQL_UPDATE" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_workshop_description(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="password" method="PHP_FUNCTION" type="varchar" length="32">
<PHP_FUNCTION>
migrate2utf8_workshop_password(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
</TABLES>
</DBMIGRATION>