I’ve taken some code designed to convert a WordPress database to UTF-8 and converted it to a MODx snippet.
It doesn’t modify the DB. Rather, it creates the SQL statements to be cut and pasted into PhpMyAdmin to do the job so it’s harmless to run the snippet itself.
Basically, the SQL converts all the text fields of the DB to blobs (remembering what they were), alters the db charset and all the table charsets, and then converts them back.
[Update - 2/22/08]
I got the index problem sorted out and the snippet now appears to output exactly the SQL statements necessary to do the conversion. The down side is that it now trashes my site content.
The content field of one of my pages has an anomalous character at about character 40 and the conversion truncates it at that point.
The same thing happens when I just go in PhpMyAdmin and convert that field to a BLOB or MEDIUMBLOB and then convert back to MEDIUMTEXT using utf8_general_ci as the collation. Converting the table and/or the db to utf8 before converting back doesn’t seem to have any effect.
It’s got nothing to do with MODx because the data is actually missing in the DB immediately after converting the field.
I’ve uploaded the new file here in case anyone wants to play with it. It’s harmless as long as you don’t paste the SQL statements into PhpMyAdmin and execute them. You can see what it would do and you can look at the source, which has some interesting code for finding text fields and then finding and dropping/restoring their respective problem indexes.
BTW, the code to put the fields back to their proper type is incomplete and should include statements for setting DEFAULT and NULL. It wouldn’t be too difficult to add this but I’m not sure there’s any point now.
It’s lucky that the anomalous character was there because, otherwise, I might not have realized that the snippet was unsafe to use.
Bob