mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
utf8 migration support scripts
This commit is contained in:
parent
bbbb201364
commit
1e4d9ff6dc
36 changed files with 4767 additions and 0 deletions
67
mod/forum/db/migrate2utf8.php
Executable file
67
mod/forum/db/migrate2utf8.php
Executable file
|
@ -0,0 +1,67 @@
|
|||
<?
|
||||
function migrate2utf8_forum_name($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$forum = get_record('forum','id',$recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($forum->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($forum->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($forum->name, $fromenc);
|
||||
|
||||
$newforum = new object;
|
||||
$newforum->id = $recordid;
|
||||
$newforum->name = $result;
|
||||
update_record('forum',$newforum);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf8_forum_intro($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$forum = get_record('forum','id',$recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($forum->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($forum->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($forum->intro, $fromenc);
|
||||
|
||||
$newforum = new object;
|
||||
$newforum->id = $recordid;
|
||||
$newforum->intro = $result;
|
||||
update_record('forum',$newforum);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
?>
|
67
mod/forum/db/migrate2utf8.xml
Executable file
67
mod/forum/db/migrate2utf8.xml
Executable file
|
@ -0,0 +1,67 @@
|
|||
<DBMIGRATION type="mod/forum" VERSION="2005120100">
|
||||
<TABLES>
|
||||
<TABLE name="forum_discussions">
|
||||
<FIELDS>
|
||||
<FIELD name="name" method="PLAIN_SQL_UPDATE" type="varchar" length="255">
|
||||
<SQL_DETECT_USER>
|
||||
SELECT fd.userid
|
||||
FROM {$CFG->prefix}forum_discussions fd
|
||||
WHERE fd.id=RECORDID
|
||||
</SQL_DETECT_USER>
|
||||
<SQL_DETECT_COURSE>
|
||||
SELECT f.course
|
||||
FROM {$CFG->prefix}forum_discussions fd
|
||||
WHERE fd.id = RECORDID
|
||||
</SQL_DETECT_COURSE>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
<TABLE name="forum_posts">
|
||||
<FIELDS>
|
||||
<FIELD name="subject" method="PLAIN_SQL_UPDATE" type="varchar" length="255">
|
||||
<SQL_DETECT_USER>
|
||||
SELECT fp.userid
|
||||
FROM {$CFG->prefix}forum_posts fp
|
||||
WHERE fp.id = RECORDID
|
||||
</SQL_DETECT_USER>
|
||||
<SQL_DETECT_COURSE>
|
||||
SELECT fd.course
|
||||
FROM {$CFG->prefix}forum_discussions fd,
|
||||
{$CFG->prefix}forum_posts fp
|
||||
WHERE fd.id = fp.discussion
|
||||
AND fp.id = RECORDID
|
||||
</SQL_DETECT_COURSE>
|
||||
</FIELD>
|
||||
<FIELD name="message" method="PLAIN_SQL_UPDATE" type="text" length="0">
|
||||
<SQL_DETECT_USER>
|
||||
SELECT fp.userid
|
||||
FROM {$CFG->prefix}forum_posts fp
|
||||
WHERE fp.id = RECORDID
|
||||
</SQL_DETECT_USER>
|
||||
<SQL_DETECT_COURSE>
|
||||
SELECT fd.course
|
||||
FROM {$CFG->prefix}forum_discussions fd,
|
||||
{$CFG->prefix}forum_posts fp
|
||||
WHERE fd.id = fp.discussion
|
||||
AND fp.id = RECORDID
|
||||
</SQL_DETECT_COURSE>
|
||||
</FIELD>
|
||||
<FIELD name="attachment" method="NO_CONV" type="varchar" length="0" />
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
<TABLE name="forum">
|
||||
<FIELDS>
|
||||
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf8_forum_name(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
<FIELD name="intro" method="PHP_FUNCTION" type="text" length="0">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf8_forum_intro(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</DBMIGRATION>
|
Loading…
Add table
Add a link
Reference in a new issue