From 16ae46f6c530579e019c7422042e6d0f659a851d Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Mon, 10 Apr 2006 06:08:13 +0000 Subject: [PATCH] migration for blogs and tags --- lib/db/migrate2utf8.php | 151 ++++++++++++++++++++++++++++++++++++++++ lib/db/migrate2utf8.xml | 33 +++++++++ 2 files changed, 184 insertions(+) diff --git a/lib/db/migrate2utf8.php b/lib/db/migrate2utf8.php index fc6260efec..3e0373a143 100755 --- a/lib/db/migrate2utf8.php +++ b/lib/db/migrate2utf8.php @@ -1,5 +1,156 @@ lang; + $courselang = null; //Non existing! + if ($post->userid) { + $userlang = get_user_lang($post->userid); + } + $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($post->subject, $fromenc); + + $newpost = new object; + $newpost->id = $recordid; + $newpost->subject = $result; + migrate2utf8_update_record('event',$newpost); + } +/// And finally, just return the converted field + return $result; +} + +function migrate2utf8_post_summary($recordid){ + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$post = get_record('post', 'id', $recordid)) { + log_the_problem_somewhere(); + return false; + } + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = null; //Non existing! + if ($post->userid) { + $userlang = get_user_lang($post->userid); + } + $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($post->summary, $fromenc); + + $newpost = new object; + $newpost->id = $recordid; + $newpost->summary = $result; + migrate2utf8_update_record('event',$newpost); + } +/// And finally, just return the converted field + return $result; +} + +function migrate2utf8_post_content($recordid){ + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$post = get_record('post', 'id', $recordid)) { + log_the_problem_somewhere(); + return false; + } + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = null; //Non existing! + if ($post->userid) { + $userlang = get_user_lang($post->userid); + } + $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($post->content, $fromenc); + + $newpost = new object; + $newpost->id = $recordid; + $newpost->content = $result; + migrate2utf8_update_record('event',$newpost); + } +/// And finally, just return the converted field + return $result; +} + +function migrate2utf8_tags_text($recordid){ + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$tags = get_record('tags', 'id', $recordid)) { + log_the_problem_somewhere(); + return false; + } + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = null; //Non existing! + if ($tags->userid) { + $userlang = get_user_lang($tags->userid); + } + $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($tags->text, $fromenc); + + $newtags = new object; + $newtags->id = $recordid; + $newtags->text = $result; + migrate2utf8_update_record('tags',$newtags); + } +/// And finally, just return the converted field + return $result; +} function migrate2utf8_event_name($recordid){ global $CFG, $globallang; diff --git a/lib/db/migrate2utf8.xml b/lib/db/migrate2utf8.xml index 60a0b3a6bd..c7e67fa2f5 100755 --- a/lib/db/migrate2utf8.xml +++ b/lib/db/migrate2utf8.xml @@ -1,5 +1,38 @@ + +
+ + + + + migrate2utf8_post_subject(RECORDID) + + + + + migrate2utf8_post_summary(RECORDID) + + + + + migrate2utf8_post_content(RECORDID) + + + + + +
+ + + + + + migrate2utf8_tags_text(RECORDID) + + + +
-- 2.39.5