From 7a2426fd29a1df0938dad9c61b4b986cdd94ae42 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 7 Nov 2005 07:46:17 +0000 Subject: [PATCH] changing the default charset of the DB too and running now only for mysql 4.1+ (no longer for 4.0, as I cant get it working there) --- setup/fix_mysql_charset.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/setup/fix_mysql_charset.php b/setup/fix_mysql_charset.php index 6a0a1490f5..26593b9995 100644 --- a/setup/fix_mysql_charset.php +++ b/setup/fix_mysql_charset.php @@ -43,26 +43,30 @@ if (!isset($GLOBALS['egw_setup']) || !is_object($GLOBALS['egw_setup'])) $GLOBALS['egw_setup']->html->show_header('',False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')'); echo '

'.'Fix mysql DB to match the eGroupWare system_charset'."

\n"; $running_standalone = true; - - echo "

DB-Type='{$GLOBALS['egw_setup']->db->Type}', eGroupWare system_charset='{$GLOBALS['egw_setup']->system_charset}', DB charset was '{$GLOBALS['egw_setup']->db_charset_was}'

\n"; } $db =& $GLOBALS['egw_setup']->db; $charset2mysql =& $GLOBALS['egw_setup']->db->Link_ID->charset2mysql; $mysql2charset = array_flip($charset2mysql); +$ServerInfo = $db->Link_ID->ServerInfo(); +$db_version = (float) $ServerInfo['version']; + +if ($running_standalone || $_REQUEST['debug']) echo "

DB-Type='{$GLOBALS['egw_setup']->db->Type}', DB-Version=$db_version ($ServerInfo[description]), eGroupWare system_charset='{$GLOBALS['egw_setup']->system_charset}', DB-connection charset was '{$GLOBALS['egw_setup']->db_charset_was}'

\n"; + $mysql_system_charset = isset($charset2mysql[$GLOBALS['egw_setup']->system_charset]) ? $charset2mysql[$GLOBALS['egw_setup']->system_charset] : $GLOBALS['egw_setup']->system_charset; - -if (substr($db->Type,0,5) == 'mysql' && $GLOBALS['egw_setup']->system_charset && $GLOBALS['egw_setup']->db_charset_was && + +if (substr($db->Type,0,5) == 'mysql' && $db_version >= 4.1 && $GLOBALS['egw_setup']->system_charset && $GLOBALS['egw_setup']->db_charset_was && $GLOBALS['egw_setup']->system_charset != $GLOBALS['egw_setup']->db_charset_was) { + $tables_modified = 'no'; + $tables = array(); $db->query("SHOW TABLE STATUS",__LINE__,__FILE__); while (($row = $db->row(true))) { $tables[$row['Name']] = $row['Collation']; } - $tables_modified = 0; foreach($tables as $table => $collation) { $columns = array(); @@ -168,10 +172,19 @@ if (substr($db->Type,0,5) == 'mysql' && $GLOBALS['egw_setup']->system_charset && ++$tables_modified; } } + // change the default charset of the DB + $db->query("SHOW CREATE DATABASE `$db->Database`",__LINE__,__FILE__); + $create_db = $db->next_record() ? $db->f(1) : ''; + if (preg_match('/CHARACTER SET ([a-z1-9_-]+) /i',$create_db,$matches) && $matches[1] != $mysql_system_charset) + { + $alter_db = "ALTER DATABASE `$db->Database` DEFAULT CHARACTER SET $mysql_system_charset"; + if ($running_standalone || $_REQUEST['debug']) echo '

'.$alter_db."

\n"; + $db->query($alter_db,__LINE__,__FILE__); + } } -if ($running_standalone) +if ($running_standalone || $_REQUEST['debug']) { echo "

$tables_modified tables changed to our system_charset {$GLOBALS['egw_setup']->system_charset}($mysql_system_charset)

\n"; - $GLOBALS['egw_setup']->html->show_footer(); + if ($running_standalone) $GLOBALS['egw_setup']->html->show_footer(); }