]> git.mjollnir.org Git - moodle.git/commitdiff
block unicode migration bugs
authortoyomoyo <toyomoyo>
Tue, 18 Apr 2006 06:17:30 +0000 (06:17 +0000)
committertoyomoyo <toyomoyo>
Tue, 18 Apr 2006 06:17:30 +0000 (06:17 +0000)
admin/utfdbmigrate.php
blocks/db/migrate2utf8.php
blocks/db/migrate2utf8.xml

index 3ad5db4118e02897f3526355695e826af1e68337..5434f002b45066278ad16a521e02d47e99c6bf06 100755 (executable)
@@ -794,10 +794,12 @@ function log_the_problem_somewhere() {  //Eloy: Nice function, perhaps we could
 }
 
 //only this function should be used during db migraton, because of addslashes at the end of the convertion
-function utfconvert($string, $enc) {
+function utfconvert($string, $enc, $slash=true) {
     global $textlib;
     if ($result = $textlib->convert($string, $enc)) {
-        $result = addslashes($result);
+        if ($slash) {
+            $result = addslashes($result);
+        }
     }
     return $result;
 }
index 6cb873e3b7840b1295d0928e23530437279051e9..5e097f038d73b5dfd2e5fbbe446eb0401ebf393d 100755 (executable)
@@ -26,8 +26,8 @@ function migrate2utf8_block_instance_configdata($recordid){
     /// We are going to use textlib facilities
         
     /// Convert the text
-        $blah->title = utfconvert($blah->title, $fromenc);
-        $blah->text = utfconvert($blah->text, $fromenc);
+        $blah->title = utfconvert($blah->title, $fromenc, false);
+        $blah->text = utfconvert($blah->text, $fromenc, false);
         
         $blockinstance->configdata = base64_encode(serialize($blah));
 
@@ -53,7 +53,7 @@ function migrate2utf8_block_instance_configdata($recordid){
     /// We are going to use textlib facilities
         
     /// Convert the text
-        $blah->title = utfconvert($blah->title, $fromenc);
+        $blah->title = utfconvert($blah->title, $fromenc, false);
 
         $blockinstance->configdata = base64_encode(serialize($blah));
 
@@ -66,6 +66,67 @@ function migrate2utf8_block_instance_configdata($recordid){
 }
 
 function migrate2utf8_block_pinned_configdata($recordid){
+global $CFG, $globallang;
 
+    $blockpinned = get_record('block_pinned','id',$recordid);
+
+    //get block instance type, we only need to worry about HTML blocks... right?????????
+
+    $blocktype = get_record('block','id',$blockpinned->blockid);
+
+    if ($blocktype -> name == 'html') {
+
+        ///find course
+        if ($globallang) {
+            $fromenc = $globallang;
+        } else {
+            $sitelang   = $CFG->lang;
+            $courselang = get_course_lang($blockpinned->pageid);  //Non existing!
+            $userlang   = get_main_teacher_lang($blockpinned->pageid); //N.E.!!
+
+            $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
+        }
+
+        $blah = unserialize(base64_decode($blockpinned->configdata));
+
+    /// We are going to use textlib facilities
+
+    /// Convert the text
+        $blah->title = utfconvert($blah->title, $fromenc, false);
+        $blah->text = utfconvert($blah->text, $fromenc, false);
+
+        $blockpinned->configdata = base64_encode(serialize($blah));
+
+        migrate2utf8_update_record('blockpinned',$blockpinned);
+
+        return $blah;
+
+    } else if ($blocktype -> name == 'rss_client'){
+
+        ///find course
+        if ($globallang) {
+            $fromenc = $globallang;
+        } else {
+            $sitelang   = $CFG->lang;
+            $courselang = get_course_lang($blockpinned->pageid);  //Non existing!
+            $userlang   = get_main_teacher_lang($blockpinned->pageid); //N.E.!!
+
+            $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
+        }
+
+        $blah = unserialize(base64_decode($blockpinned->configdata));
+
+    /// We are going to use textlib facilities
+
+    /// Convert the text
+        $blah->title = utfconvert($blah->title, $fromenc, false);
+
+        $blockpinned->configdata = base64_encode(serialize($blah));
+
+        migrate2utf8_update_record('blockpinned',$blockblockpinned);
+
+        return $blah;
+
+    }
 }
 ?>
index d925f27d9cacb46fcbbea991e7be68a4b16395e0..c6cbd2ff1be975b6da54ee209cb1a7ea9fa32c65 100755 (executable)
@@ -22,7 +22,7 @@
         <FIELD name="position" method="NO_CONV" type="varchar" length="10" />
         <FIELD name="configdata" method="PHP_FUNCTION" type="text" length="0">
           <PHP_FUNCTION>
-            migrate2utf8_block_instance_configdata(RECORDID)
+            migrate2utf8_block_pinned_configdata(RECORDID)
           </PHP_FUNCTION>
         </FIELD>
       </FIELDS>