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
172
mod/exercise/db/migrate2utf8.php
Executable file
172
mod/exercise/db/migrate2utf8.php
Executable file
|
@ -0,0 +1,172 @@
|
|||
<?
|
||||
function migrate2utf8_exercise_elements_description($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$SQL = "SELECT ex.course
|
||||
FROM {$CFG->prefix}exercise ex,
|
||||
{$CFG->prefix}exercise_elements exe
|
||||
WHERE ex.id = exe.exerciseid
|
||||
AND exe.id = $recordid";
|
||||
|
||||
if (!$exercise = get_record_sql($SQL)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$exerciseelement = get_record('exercise_elements','id',$recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($exercise->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($exercise->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($exerciseelement->description, $fromenc);
|
||||
|
||||
$newexerciseelement = new object;
|
||||
$newexerciseelement->id = $recordid;
|
||||
$newexerciseelement->description = $result;
|
||||
update_record('exercise_elements',$newexerciseelement);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf8_exercise_grades_feedback($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$SQL = "SELECT ex.course
|
||||
FROM {$CFG->prefix}exercise ex,
|
||||
{$CFG->prefix}exercise_rubrics exr
|
||||
WHERE ex.id = exr.exerciseid
|
||||
AND exr.id = $recordid";
|
||||
|
||||
if (!$exercise = get_record_sql($SQL)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$exercisegrade = get_record('exercise_grades','id',$recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($exercise->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($exercise->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($exercisegrade->feedback, $fromenc);
|
||||
|
||||
$newexercisegrade = new object;
|
||||
$newexercisegrade->id = $recordid;
|
||||
$newexercisegrade->feedback = $result;
|
||||
update_record('exercise_grades',$newexercisegrade);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf8_exercise_rubrics_description($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$SQL = "SELECT ex.course
|
||||
FROM {$CFG->prefix}exercise ex,
|
||||
{$CFG->prefix}exercise_rubrics exr
|
||||
WHERE ex.id = exr.exerciseid
|
||||
AND exr.id = $recordid";
|
||||
|
||||
if (!$exercise = get_record_sql($SQL)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$exerciserubric = get_record('exercise_rubrics','id',$recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($exercise->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($exercise->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($exerciserubric->description, $fromenc);
|
||||
|
||||
$newexerciserubric = new object;
|
||||
$newexerciserubric->id = $recordid;
|
||||
$newexerciserubric->description = $result;
|
||||
update_record('exercise_rubrics',$newexerciserubric);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf8_exercise_name($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$exercise = get_record('exercise','id',$recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($exercise->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($exercise->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($exercise->name, $fromenc);
|
||||
|
||||
$newexercise = new object;
|
||||
$newexercise->id = $recordid;
|
||||
$newexercise->name = $result;
|
||||
update_record('exercise',$newexercise);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf8_exercise_password($recordid){
|
||||
global $CFG;
|
||||
|
||||
///um
|
||||
}
|
||||
?>
|
95
mod/exercise/db/migrate2utf8.xml
Executable file
95
mod/exercise/db/migrate2utf8.xml
Executable file
|
@ -0,0 +1,95 @@
|
|||
<DBMIGRATION type="mod/exercise" VERSION="2005120100">
|
||||
<TABLES>
|
||||
<TABLE name="exercise_assessments">
|
||||
<FIELDS>
|
||||
<FIELD name="generalcomment" method="PLAIN_SQL_UPDATE" type="text" length="0">
|
||||
<SQL_DETECT_USER>
|
||||
SELECT exa.userid
|
||||
FROM {$CFG->prefix}exercise_assessments exa
|
||||
WHERE exa.id = RECORDID
|
||||
</SQL_DETECT_USER>
|
||||
<SQL_DETECT_COURSE>
|
||||
SELECT ex.course
|
||||
FROM {$CFG->prefix}exercise ex,
|
||||
{$CFG->prefix}exercise_assessments exa
|
||||
WHERE ex.id = exa.exerciseid
|
||||
AND exa.id = RECORDID
|
||||
</SQL_DETECT_COURSE>
|
||||
</FIELD>
|
||||
<FIELD name="teachercomment" method="PLAIN_SQL_UPDATE" type="text" length="0">
|
||||
<SQL_DETECT_USER>
|
||||
SELECT exa.userid
|
||||
FROM {$CFG->prefix}exercise_assessments exa
|
||||
WHERE exa.id = RECORDID
|
||||
</SQL_DETECT_USER>
|
||||
<SQL_DETECT_COURSE>
|
||||
SELECT ex.course
|
||||
FROM {$CFG->prefix}exercise ex,
|
||||
{$CFG->prefix}exercise_assessments exa
|
||||
WHERE ex.id = exa.exerciseid
|
||||
AND exa.id = RECORDID
|
||||
</SQL_DETECT_COURSE>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
<TABLE name="exercise_elements">
|
||||
<FIELDS>
|
||||
<FIELD name="description" method="PHP_FUNCTION" type="text" length="0">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_exercise_elements_description(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
<TABLE name="exercise_grades">
|
||||
<FIELDS>
|
||||
<FIELD name="feedback" method="PHP_FUNCTION" type="text" length="0">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_exercise_grades_feedback(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
<TABLE name="exercise_rubrics">
|
||||
<FIELDS>
|
||||
<FIELD name="description" method="PHP_FUNCTION" type="text" length="0">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_exercise_rubrics_description(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
<TABLE name="exercise_submissions">
|
||||
<FIELDS>
|
||||
<FIELD name="title" method="PLAIN_SQL_UPDATE" type="varchar" length="100">
|
||||
<SQL_DETECT_USER>
|
||||
SELECT exs.userid
|
||||
FROM {$CFG->prefix}exercise_submissions exs
|
||||
WHERE exs.id = RECORDID
|
||||
</SQL_DETECT_USER>
|
||||
<SQL_DETECT_COURSE>
|
||||
SELECT ex.course
|
||||
FROM {$CFG->prefix}exercise ex,
|
||||
{$CFG->prefix}exercise_submissions exs
|
||||
WHERE ex.id = exs.exerciseid
|
||||
AND exs.id = RECORDID
|
||||
</SQL_DETECT_COURSE>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
<TABLE name="exercise">
|
||||
<FIELDS>
|
||||
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_exercise_name(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
<FIELD name="password" method="PHP_FUNCTION" type="varchar" length="32">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_exercise_password(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</DBMIGRATION>
|
Loading…
Add table
Add a link
Reference in a new issue