]> git.mjollnir.org Git - moodle.git/commitdiff
migration for blogs and tags
authortoyomoyo <toyomoyo>
Mon, 10 Apr 2006 06:08:13 +0000 (06:08 +0000)
committertoyomoyo <toyomoyo>
Mon, 10 Apr 2006 06:08:13 +0000 (06:08 +0000)
lib/db/migrate2utf8.php
lib/db/migrate2utf8.xml

index fc6260efec4bc842e28516a2f6c0bb88c39cff92..3e0373a1437b8170d1f46174a3ca7676735e822c 100755 (executable)
@@ -1,5 +1,156 @@
 <?php // $Id$
 
+function migrate2utf8_post_subject($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->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;
index 60a0b3a6bd38196f1e8bc2c45aa9bb48ad59c5ed..c7e67fa2f5746b09a105e06e7fc872104fa8697c 100755 (executable)
@@ -1,5 +1,38 @@
 <DBMIGRATION type="lib" VERSION="2005120100">
   <TABLES>
+    <TABLE name="blog_tag_instance" />
+    <TABLE name="post">
+      <FIELDS>
+        <FIELD name="module" method="NO_CONV" type="varchar" length="20" dropindex="post_module_idx" addindex="post_module_idx(module(20))"/>
+        <FIELD name="subject" method="PHP_FUNCTION" type="varchar" length="128" dropindex="post_subject_idx" addindex=" post_subject_idx(subject(128))">
+          <PHP_FUNCTION>
+            migrate2utf8_post_subject(RECORDID)
+          </PHP_FUNCTION>
+        </FIELD>
+        <FIELD name="summary" method="PHP_FUNCTION" type="longtext" length="0">
+          <PHP_FUNCTION>
+            migrate2utf8_post_summary(RECORDID)
+          </PHP_FUNCTION>
+        </FIELD>
+        <FIELD name="content" method="PHP_FUNCTION" type="longtext" length="0">
+          <PHP_FUNCTION>
+            migrate2utf8_post_content(RECORDID)
+          </PHP_FUNCTION>
+        </FIELD>
+        <FIELD name="uniquehash" method="NO_CONV" type="varchar" length="128" />
+        <FIELD name="publishstate" method="NO_CONV" type="enum('draft', 'site', 'public')" length="0" default="draft" />
+      </FIELDS>
+    </TABLE>
+    <TABLE name="tags">
+      <FIELDS>
+        <FIELD name="type" method="NO_CONV" type="varchar" length="255" />
+        <FIELD name="text" method="PHP_FUNCTION" type="varchar" length="255">
+          <PHP_FUNCTION>
+            migrate2utf8_tags_text(RECORDID)
+          </PHP_FUNCTION>
+        </FIELD>
+      </FIELDS>
+    </TABLE>
     <TABLE name="config">
       <FIELDS>
         <FIELD name="name" method="NO_CONV" type="varchar" length="255" dropindex="name" adduniqueindex="name (name(255))"/>