diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/access.class.php | 2 | ||||
-rw-r--r-- | lib/class/dba.class.php | 70 | ||||
-rw-r--r-- | lib/class/update.class.php | 16 | ||||
-rw-r--r-- | lib/gettext.php | 2 |
4 files changed, 87 insertions, 3 deletions
diff --git a/lib/class/access.class.php b/lib/class/access.class.php index 734c7d76..64719141 100644 --- a/lib/class/access.class.php +++ b/lib/class/access.class.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2007 Ampache.org + Copyright (c) Ampache.org All Rights Reserved This program is free software; you can redistribute it and/or diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php index e9d0304d..6ead8b8b 100644 --- a/lib/class/dba.class.php +++ b/lib/class/dba.class.php @@ -251,6 +251,76 @@ class Dba { } // auto_init + /** + * reset_db_charset + * This cruises through the database and trys to set the charset to the current + * site charset, this is an admin function that can be run by an administrator + * this can mess up data if you switch between charsets that are not overlapping + * a catalog verify must be re-run to correct them + */ + public static function reset_db_charset() { + + // MySQL translte real charset names into fancy smancy MySQL land names + switch (strtoupper(Config::get('site_charset'))) { + case 'EUC-KR': + $target_charset = 'euckr'; + $target_collation = 'euckr_korean_ci'; + break; + case 'CP932': + $target_charset = 'sjis'; + $target_collation = 'sjis_japanese_ci'; + break; + case 'KOI8-U': + $target_charset = 'koi8u'; + $target_collation = 'koi8u_general_ci'; + break; + case 'KOI8-R': + $target_charset = 'koi8r'; + $target_collation = 'koi8r_general_ci'; + break; + case 'ISO-8859': + $target_charset = 'latin2'; + $target_collation = 'latin2_general_ci'; + break; + default; + case 'UTF-8': + $target_charset = 'utf8'; + $target_collation = 'utf8_unicode_ci'; + break; + } // end mysql charset translation + + // Alter the charset for the entire database + $sql = "ALTER DATABASE `" . Config::get('database_name') . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; + $db_results = Dba::query($sql); + + $sql = "SHOW TABLES"; + $db_results = Dba::query($sql); + + // Go through the tables! + while ($row = Dba::fetch_row($db_results)) { + $sql = "DESCRIBE `" . $row['0'] . "`"; + $describe_results = Dba::query($sql); + + // Change the tables default charset and colliation + $sql = "ALTER TABLE `" . $row['0'] . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; + $alter_table = Dba::query($sql); + + // Itterate through the columns of the table + while ($table = Dba::fetch_assoc($describe_results)) { + if (strstr($table['Type'],'varchar') OR strstr($table['Type'],'enum') OR strstr($table['Table'],'text')) { + $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset; + $charset_results = Dba::query($sql); + if (!$charset_results) { + debug_event('CHARSET','Unable to update the charset of ' . $table['Field'] . '.' . $table['Type'] . ' to ' . $target_charset,'3'); + } // if it fails + } // if its a varchar + } // end columns + + } // end tables + + + } // reset_db_charset + } // dba class ?> diff --git a/lib/class/update.class.php b/lib/class/update.class.php index e40c9336..1a96b978 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -1211,24 +1211,34 @@ class Update { switch (strtoupper(Config::get('site_charset'))) { case 'EUC-KR': $target_charset = 'euckr'; + $target_collation = 'euckr_korean_ci'; break; case 'CP932': $target_charset = 'sjis'; + $target_collation = 'sjis_japanese_ci'; break; case 'KOI8-U': $target_charset = 'koi8u'; + $target_collation = 'koi8u_general_ci'; break; case 'KOI8-R': $target_charset = 'koi8r'; + $target_collation = 'koi8r_general_ci'; break; case 'ISO-8859': $target_charset = 'latin2'; + $target_collation = 'latin2_general_ci'; break; default; case 'UTF-8': $target_charset = 'utf8'; + $target_collation = 'utf8_unicode_ci'; break; } // end mysql charset translation + + // Alter the charset for the entire database + $sql = "ALTER DATABASE `" . Config::get('database_name') . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; + $db_results = Dba::query($sql); $sql = "SHOW TABLES"; $db_results = Dba::query($sql); @@ -1238,9 +1248,13 @@ class Update { $sql = "DESCRIBE `" . $row['0'] . "`"; $describe_results = Dba::query($sql); + // Change the tables default charset and colliation + $sql = "ALTER TABLE `" . $row['0'] . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; + $alter_table = Dba::query($sql); + // Itterate through the columns of the table while ($table = Dba::fetch_assoc($describe_results)) { - if (strstr($table['Type'],'varchar')) { + if (strstr($table['Type'],'varchar') OR strstr($table['Type'],'enum') OR strstr($table['Table'],'text')) { $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset; $charset_results = Dba::query($sql); if (!$charset_results) { diff --git a/lib/gettext.php b/lib/gettext.php index 810b9664..083c4919 100644 --- a/lib/gettext.php +++ b/lib/gettext.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2006 Ampache.org + Copyright (c) Ampache.org All Rights Reserved This program is free software; you can redistribute it and/or |