mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
utf8 migration support scripts
This commit is contained in:
parent
bbbb201364
commit
1e4d9ff6dc
36 changed files with 4767 additions and 0 deletions
133
mod/resource/db/migrate2utf8.php
Executable file
133
mod/resource/db/migrate2utf8.php
Executable file
|
@ -0,0 +1,133 @@
|
|||
<?
|
||||
function migrate2utf_resource_name($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$resource = get_record('resource','id',$recordid) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($resource->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($resource->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($resource->name, $fromenc);
|
||||
|
||||
$newresource = new object;
|
||||
$newresource->id = $recordid;
|
||||
$newresource->name = $result;
|
||||
update_record('resource',$newresource);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf_resource_reference($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$resource = get_record('resource','id',$recordid) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($resource->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($resource->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($resource->reference, $fromenc);
|
||||
|
||||
$newresource = new object;
|
||||
$newresource->id = $recordid;
|
||||
$newresource->reference = $result;
|
||||
update_record('resource',$newresource);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf_resource_summary($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$resource = get_record('resource','id',$recordid) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($resource->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($resource->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($resource->summary, $fromenc);
|
||||
|
||||
$newresource = new object;
|
||||
$newresource->id = $recordid;
|
||||
$newresource->summary = $result;
|
||||
update_record('resource',$newresource);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
|
||||
function migrate2utf_resource_alltext($recordid){
|
||||
global $CFG;
|
||||
|
||||
/// Some trivial checks
|
||||
if (empty($recordid)) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$resource = get_record('resource','id',$recordid) {
|
||||
log_the_problem_somewhere();
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitelang = $CFG->lang;
|
||||
$courselang = get_course_lang($resource->course); //Non existing!
|
||||
$userlang = get_main_teacher_lang($resource->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($resource->alltext, $fromenc);
|
||||
|
||||
$newresource = new object;
|
||||
$newresource->id = $recordid;
|
||||
$newresource->alltext = $result;
|
||||
update_record('resource',$newresource);
|
||||
/// And finally, just return the converted field
|
||||
return $result;
|
||||
}
|
||||
?>
|
31
mod/resource/db/migrate2utf8.xml
Executable file
31
mod/resource/db/migrate2utf8.xml
Executable file
|
@ -0,0 +1,31 @@
|
|||
<DBMIGRATION type="mod/resource" VERSION="2005120100">
|
||||
<TABLES>
|
||||
<TABLE name="resource">
|
||||
<FIELDS>
|
||||
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf8_resource_name(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
<FIELD name="type" method="NO_CONV" type="varchar" length="30" />
|
||||
<FIELD name="reference" method="PHP_FUNCTION" type="varchar" length="255">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf8_resource_reference(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
<FIELD name="summary" method="PHP_FUNCTION" type="varchar" length="255">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf8_resource_summary(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
<FIELD name="alltext" method="PHP_FUNCTION" type="varchar" length="255">
|
||||
<PHP_FUNCTION>
|
||||
migrate2utf8_resource_alltext(RECORDID)
|
||||
</PHP_FUNCTION>
|
||||
</FIELD>
|
||||
<FIELD name="popup" method="NO_CONV" type="text" length="0" />
|
||||
<FIELD name="options" method="NO_CONV" type="varchar" length="255" />
|
||||
</FIELDS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</DBMIGRATION>
|
Loading…
Add table
Add a link
Reference in a new issue