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
110
mod/choice/db/migrate2utf8.php
Executable file
110
mod/choice/db/migrate2utf8.php
Executable file
|
@ -0,0 +1,110 @@
|
|||
<?
|
||||
function migrate2utf8_choice_options_text($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$SQL = "SELECT ch.*
|
||||
FROM {$CFG->prefix}choice ch,
|
||||
{$CFG->prefix}choice_options cho
|
||||
WHERE ch.id = cho.choiceid
|
||||
AND cho.id = $recordid";
|
||||
|
||||
if (!$choice = get_record_sql($SQL)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$choiceoption = get_record('choice_option','id',$recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($choice->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($choice->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($choiceotion->text, $fromenc);
|
||||
|
||||
$newchoiceoption = new object;
|
||||
$newchoiceoption->id = $recordid;
|
||||
$newchoiceoption->text = $result;
|
||||
update_record('choice_option',$newchoiceoption);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf8_choice_name($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
if (!$choice = get_record('choice', 'id', $recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($choice->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($choice->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($choice->name, $fromenc);
|
||||
|
||||
$newchoice = new object;
|
||||
$newchoice->id = $recordid;
|
||||
$newchoice->name = $result;
|
||||
update_record('choice',$newchoice);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf8_choice_text($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
if (!$choice = get_record('choice', 'id', $recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($choice->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($choice->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($choice->text, $fromenc);
|
||||
|
||||
$newchoice = new object;
|
||||
$newchoice->id = $recordid;
|
||||
$newchoice->text = $result;
|
||||
update_record('choice',$newchoice);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
?>
|
27
mod/choice/db/migrate2utf8.xml
Executable file
27
mod/choice/db/migrate2utf8.xml
Executable file
|
@ -0,0 +1,27 @@
|
|||
<DBMIGRATION type="mod/choice" VERSION="2005120100">
|
||||
<TABLES>
|
||||
<TABLE name="choice_options">
|
||||
<FIELDS>
|
||||
<FIELD name="text" method="PHP_FUNCTION" type="text" length="0">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_choice_options_text(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
<TABLE name="choice">
|
||||
<FIELDS>
|
||||
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_choice_name(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
<FIELD name="text" method="PHP_FUNCTION" type="text" length="0">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_choice_text(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</DBMIGRATION>
|
Loading…
Add table
Add a link
Reference in a new issue