From 1b19e8107e17141f9b93437982abeb8dd07ae0be Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Fri, 6 Oct 2006 06:04:32 +0000 Subject: [PATCH] fix for MDL-6859, MDL-6860 --- enrol/authorize/db/migrate2utf8.xml | 3 +- lib/db/migrate2utf8.php | 196 ++++++++++++++++++++++++++++ lib/db/migrate2utf8.xml | 60 ++++++++- mod/data/db/migrate2utf8.php | 37 ++++++ mod/data/db/migrate2utf8.xml | 5 + mod/wiki/db/migrate2utf8.xml | 17 +++ 6 files changed, 311 insertions(+), 7 deletions(-) diff --git a/enrol/authorize/db/migrate2utf8.xml b/enrol/authorize/db/migrate2utf8.xml index 61a0ec90c5..02fad90e88 100755 --- a/enrol/authorize/db/migrate2utf8.xml +++ b/enrol/authorize/db/migrate2utf8.xml @@ -6,12 +6,13 @@ + - +
diff --git a/lib/db/migrate2utf8.php b/lib/db/migrate2utf8.php index 15a3ee5a94..dffbc9f89b 100755 --- a/lib/db/migrate2utf8.php +++ b/lib/db/migrate2utf8.php @@ -228,6 +228,164 @@ function migrate2utf8_user($fields, $crash, $debug, $maxrecords, $done, $tablest } +function migrate2utf8_user_info_category_name($recordid) { + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$uic = get_record('user_info_category', 'id', $recordid)) { + log_the_problem_somewhere(); + return false; + } + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = null; //Non existing! + $userlang = null; // Non existing + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// Initialise $result + $result = $uic->name; + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($uic->name, $fromenc); + + $newuic = new object; + $newuic->id = $recordid; + $newuic->name = $result; + migrate2utf8_update_record('user_info_category',$newuic); + } +/// And finally, just return the converted field + return $result; +} + +function migrate2utf8_user_info_data_data($recordid) { + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$uid = get_record('user_info_data', 'id', $recordid)) { + log_the_problem_somewhere(); + return false; + } + + $user = get_record_sql("SELECT u.lang, u.lang + FROM {$CFG->prefix}user u, + {$CFG->prefix}user_info_data uid + WHERE u.id = uid.userid + AND uid.id = $recordid"); + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = null; //Non existing! + $userlang = $user->lang; // Non existing + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// Initialise $result + $result = $uid->data; + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($uic->data, $fromenc); + + $newuid = new object; + $newuid->id = $recordid; + $newuid->data = $result; + migrate2utf8_update_record('user_info_data',$newuid); + } +/// And finally, just return the converted field + return $result; +} + +function migrate2utf8_user_info_field_name($recordid) { + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$uif = get_record('user_info_field', 'id', $recordid)) { + log_the_problem_somewhere(); + return false; + } + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = null; //Non existing! + $userlang = null; // Non existing + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// Initialise $result + $result = $uif->name; + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($uif->name, $fromenc); + $newuif = new object; + $newuif->id = $recordid; + $newuif->name = $result; + migrate2utf8_update_record('user_info_field',$newuif); + } +/// And finally, just return the converted field + return $result; +} + +function migrate2utf8_user_info_field_defaultdata($recordid) { + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$uif = get_record('user_info_field', 'id', $recordid)) { + log_the_problem_somewhere(); + return false; + } + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = null; //Non existing! + $userlang = null; // Non existing + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// Initialise $result + $result = $uif->name; + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($uif->defaultdata, $fromenc); + $newuif = new object; + $newuif->id = $recordid; + $newuif->defaultdata = $result; + migrate2utf8_update_record('user_info_field',$newuif); + } +/// And finally, just return the converted field + return $result; +} function migrate2utf8_role_name($recordid){ global $CFG, $globallang; @@ -267,6 +425,44 @@ function migrate2utf8_role_name($recordid){ return $result; } +function migrate2utf8_role_shortname($recordid){ + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$role = get_record('role', 'id', $recordid)) { + log_the_problem_somewhere(); + return false; + } + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = null; //Non existing! + $userlang = null; // Non existing + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// Initialise $result + $result = $role->name; + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($role->shortname, $fromenc); + + $newrole = new object; + $newrole->id = $recordid; + $newrole->shortname = $result; + migrate2utf8_update_record('role',$newrole); + } +/// And finally, just return the converted field + return $result; +} + function migrate2utf8_role_description($recordid){ global $CFG, $globallang; diff --git a/lib/db/migrate2utf8.xml b/lib/db/migrate2utf8.xml index ee08b15d21..d13069dacf 100755 --- a/lib/db/migrate2utf8.xml +++ b/lib/db/migrate2utf8.xml @@ -9,6 +9,39 @@ +
+ + + + migrate2utf8_user_info_category_name(RECORDID) + + + +
+ + + + + migrate2utf8_user_info_data_data(RECORDID) + + + +
+ + + + + migrate2utf8_user_info_field_name(RECORDID) + + + + + + migrate2utf8_user_info_field_defaultdata(RECORDID) + + + +
@@ -16,6 +49,11 @@ migrate2utf8_role_name(RECORDID) + + + migrate2utf8_role_shortname(RECORDID) + + migrate2utf8_role_description(RECORDID) @@ -23,7 +61,6 @@
-
@@ -31,8 +68,7 @@ -
- + @@ -349,9 +385,21 @@
- -
-
+
+ + + +
+ + + + +
+ + + + +
diff --git a/mod/data/db/migrate2utf8.php b/mod/data/db/migrate2utf8.php index 6e277964a8..8e51dfb17b 100755 --- a/mod/data/db/migrate2utf8.php +++ b/mod/data/db/migrate2utf8.php @@ -405,6 +405,43 @@ function migrate2utf8_data_csstemplate($recordid){ return $result; } +function migrate2utf8_data_jstemplate($recordid){ + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$data = get_record('data','id',$recordid)) { + log_the_problem_somewhere(); + return false; + } + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = get_course_lang($data->course); //Non existing! + $userlang = get_main_teacher_lang($data->course); //N.E.!! + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// We are going to use textlib facilities + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($data->jstemplate, $fromenc); + + $newdata= new object; + $newdata->id = $recordid; + $newdata->jstemplate = $result; + migrate2utf8_update_record('data',$newdata); + } +/// And finally, just return the converted field + return $result; +} function migrate2utf8_data_listtemplateheader($recordid){ global $CFG, $globallang; diff --git a/mod/data/db/migrate2utf8.xml b/mod/data/db/migrate2utf8.xml index 85bd0715b1..991b649462 100755 --- a/mod/data/db/migrate2utf8.xml +++ b/mod/data/db/migrate2utf8.xml @@ -153,6 +153,11 @@ migrate2utf_data_csstemplate(RECORDID) + + + migrate2utf_data_csstemplate(RECORDID) + + migrate2utf_data_addtemplate(RECORDID) diff --git a/mod/wiki/db/migrate2utf8.xml b/mod/wiki/db/migrate2utf8.xml index 8612f0d7e7..83c9bd13d6 100755 --- a/mod/wiki/db/migrate2utf8.xml +++ b/mod/wiki/db/migrate2utf8.xml @@ -104,5 +104,22 @@
+ + + + SELECT wl.userid + FROM {$CFG->prefix}wiki_locks wl + WHERE wl.id=RECORDID + + + SELECT w.course + FROM {$CFG->prefix}wiki w, + {$CFG->prefix}wiki_locks wl + WHERE w.id = wl.wikiid + AND wl.id = RECORDID + + + +
-- 2.39.5