Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

UTF-8 contrib: Difference between revisions

From MoodleDocs
Line 25: Line 25:
==Manually converting a table to UTF-8==
==Manually converting a table to UTF-8==


If you have extra tables that contain text in English or UTF encoding from Moodle 1.5,
If you have extra tables that contain text in '''English''' or '''UTF encoding''' from Moodle 1.5,
and you want to convert them manually to be used under 1.6, here is a procedure:
and you want to convert them manually to be used under 1.6, you can do it using PhpMyAdmin (or direct SQL) here is a procedure: (Pleaes make a backup first)
 
# For every textual field in the table, (i.e. varchar, char, text, longtext, enum etc), you need to change the column encoding to UTF8.
 
Before you can change the column encoding to UTF8, you have to make sure that this column is not associated with any index. If it is, you need to drop the index(es), and add them back later.
 
The SQL to drop an index is
 
ALTER TABLE 'tablename' DROP INDEX 'indexname';
 
The SQLs to change column encoding to UTF8 is
 
ALTER TABLE 'tablename' CHANGE 'fieldname' 'fieldname' LONGBLOG
ALTER TABLE 'tablename' CHANGE 'fieldname' 'fieldname' original_type CHARACTER SET utf8 NOT NULL DEFAULT defaultvalue.
 
Example,
 


#





Revision as of 03:09, 21 April 2006

UTF-8 migration > Contrib

How to make your contrib module work for the UTF-8 migration process

The UTF-8 migration script traverse Moodle modules same way as the module upgrade process.

For the purpose of making Moodle totally UTF-8, every field of type (varchar, text, enum) will need to be converted to UTF-8.

To do this, you need to put 2 files in the db folder, where the mysql.sql and postgres.sql files are.

  • migrate2utf8.xml defines what fields to be converted. Every field needs a type and a length, and if applicable, index information (see below). There are 3 methods associated with each field:
  1. -NO_CONV is for those fields that could only contain English Chars, written by Moodle.
  2. -PLAIN_SQL_UPDATE is used when you can find both the user language and course language for that record using 1 SQL conveniently. If you use this method you must include both sqls for the user lang and the course lang.
  3. -PHP_FUNCTION is used when the detection of userlang or courselang is more difficult, or more sophisticated methods are needed for the conversion (e.g. serialized objects, or when you need to append _utf8 to a lang field etc)
  • migrate2utf8.php defines each php function included to do the conversion.

Please look at forum/db for the exact formats of these files.

All indexes need to be dropped prior to (or at the same time) the processing this field. This can be done using dropindex or dropprimary. After the field is processed, you need to add the indexes back using addindex, adduniqueindex, or addprimary. If you don't have enough fields in the table to do addindex or dropindex, you can add arbitrary number of dummy fields (see scorm/db/migrate2utf8.xlm)

To test the migration, please don't forget to turn debug on.

Manually converting a table to UTF-8

If you have extra tables that contain text in English or UTF encoding from Moodle 1.5, and you want to convert them manually to be used under 1.6, you can do it using PhpMyAdmin (or direct SQL) here is a procedure: (Pleaes make a backup first)

  1. For every textual field in the table, (i.e. varchar, char, text, longtext, enum etc), you need to change the column encoding to UTF8.

Before you can change the column encoding to UTF8, you have to make sure that this column is not associated with any index. If it is, you need to drop the index(es), and add them back later.

The SQL to drop an index is

ALTER TABLE 'tablename' DROP INDEX 'indexname';

The SQLs to change column encoding to UTF8 is

ALTER TABLE 'tablename' CHANGE 'fieldname' 'fieldname' LONGBLOG ALTER TABLE 'tablename' CHANGE 'fieldname' 'fieldname' original_type CHARACTER SET utf8 NOT NULL DEFAULT defaultvalue.

Example,