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
65
mod/assignment/db/migrate2utf8.php
Executable file
65
mod/assignment/db/migrate2utf8.php
Executable file
|
@ -0,0 +1,65 @@
|
|||
<?
|
||||
function migrate2utf8_assignment_name($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
if (!$assignment = get_record('assignment', 'id', $recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($assignment->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($assignment->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($assignment->name, $fromenc);
|
||||
|
||||
$newassignment = new object;
|
||||
$newassignment->id = $recordid;
|
||||
$newassignment->name = $result;
|
||||
update_record('assignment',$newassignment);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf8_assignment_description($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
if (!$assignment = get_record('assignment', 'id', $recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($assignment->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($assignment->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($assignment->description, $fromenc);
|
||||
|
||||
$newassignment = new object;
|
||||
$newassignment->id = $recordid;
|
||||
$newassignment->description = $result;
|
||||
update_record('assignment',$newassignment);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
?>
|
65
mod/assignment/db/migrate2utf8.xml
Executable file
65
mod/assignment/db/migrate2utf8.xml
Executable file
|
@ -0,0 +1,65 @@
|
|||
<DBMIGRATION type="mod/assignment" VERSION = "2005120100">
|
||||
<TABLES>
|
||||
<TABLE name="assignment_submissions">
|
||||
<FIELDS>
|
||||
<FIELD name="data1" method="PLAIN_SQL_UPDATE" type="text" length="0">
|
||||
<SQL_DETECT_USER>
|
||||
SELECT ass.userid
|
||||
FROM {$CFG->prefix}assignment_submissions ass
|
||||
WHERE ass.id=RECORDID
|
||||
</SQL_DETECT_USER>
|
||||
<SQL_DETECT_COURSE>
|
||||
SELECT a.course
|
||||
FROM {$CFG->prefix}assignment a,
|
||||
{$CFG->prefix}assignment_submissions ass
|
||||
WHERE a.id = ass.assignment
|
||||
AND ass.id = RECORDID
|
||||
</SQL_DETECT_COURSE>
|
||||
</FIELD>
|
||||
<FIELD name="data2" method="PLAIN_SQL_UPDATE" type="text" length="0">
|
||||
<SQL_DETECT_USER>
|
||||
SELECT ass.userid
|
||||
FROM {$CFG->prefix}assignment_submissions ass
|
||||
WHERE ass.id=RECORDID
|
||||
</SQL_DETECT_USER>
|
||||
<SQL_DETECT_COURSE>
|
||||
SELECT a.course
|
||||
FROM {$CFG->prefix}assignment a,
|
||||
{$CFG->prefix}assignment_submissions ass
|
||||
WHERE a.id = ass.assignment
|
||||
AND ass.id = RECORDID
|
||||
</SQL_DETECT_COURSE>
|
||||
</FIELD>
|
||||
<FIELD name="comment" method="PLAIN_SQL_UPDATE" type="text" length="0">
|
||||
<SQL_DETECT_USER>
|
||||
SELECT ass.teacher as userid
|
||||
FROM {$CFG->prefix}assignment_submissions ass
|
||||
WHERE ass.id=RECORDID
|
||||
</SQL_DETECT_USER>
|
||||
<SQL_DETECT_COURSE>
|
||||
SELECT a.course
|
||||
FROM {$CFG->prefix}assignment a,
|
||||
{$CFG->prefix}assignment_submissions ass
|
||||
WHERE a.id = ass.assignment
|
||||
AND ass.id = RECORDID
|
||||
</SQL_DETECT_COURSE>
|
||||
</FIELD>
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
<TABLE name="assignment">
|
||||
<FIELDS>
|
||||
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_assignment_name(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
<FIELD name="description" method="PHP_FUNCTION" type="text" length="0">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf_assignment_description(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
<FIELD name="assignmenttype" method="NO_CONV" type="varchar" length="50" />
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</DBMIGRATION>
|
Loading…
Add table
Add a link
Reference in a new issue