array( 'noheader' => True, 'nonavbar' => True, 'currentapp' => 'home', 'noapi' => True )); include('./inc/functions.inc.php'); // Authorize the user to use setup app and load the database // Does not return unless user is authorized if (!$GLOBALS['egw_setup']->auth('Config') || @$_POST['cancel']) { Header('Location: index.php'); exit; } $GLOBALS['egw_setup']->loaddb(); $tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup'); $setup_tpl = CreateObject('phpgwapi.Template',$tpl_root); $setup_tpl->set_file(array( 'T_head' => 'head.tpl', 'T_footer' => 'footer.tpl', )); $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); $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 && $GLOBALS['egw_setup']->system_charset != $GLOBALS['egw_setup']->db_charset_was) { $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(); $db->query("SHOW FULL FIELDS FROM `$table`",__LINE__,__FILE__); while(($row = $db->row(true))) { $columns[] = $row; } //echo $table; _debug_array($columns); $fulltext = $fulltext_back = array(); $db->query("SHOW KEYS FROM `$table`",__LINE__,__FILE__); while(($row = $db->row(true))) { if ($row['Index_type'] == 'FULLTEXT') { $fulltext[$row['Column_name']] = $row['Key_name']; } } $alter_table = $alter_table_back = array(); foreach($columns as $column) { if ($column['Collation'] && preg_match('/^(char|varchar|.*text)\(?([0-9]*)\)?$/i',$column['Type'],$matches)) { list(,$type,$size) = $matches; list($charset) = explode('_',$column['Collation']); if (isset($mysql2charset[$charset])) $charset = $mysql2charset[$charset]; if ($charset != $GLOBALS['egw_setup']->system_charset) { $col = $column['Field']; if ($type == 'varchar' || $type == 'char') // old schema_proc (pre 1.0.1) used also char { $type = 'varchar('.$size.')'; $bintype = 'varbinary('.$size.')'; } else { $bintype = str_replace('text','blob',$type); } //echo "

$table.$col $type CHARACTER SET $charset $default $null

\n"; $default = !is_null($column['Default']) ? "DEFAULT '".$column['Default']."'" : ''; $null = $column['Null'] ? 'NULL' : 'NOT NULL'; if (isset($fulltext[$col])) { $idx_name = $fulltext[$col]; $idx_cols = array(); foreach($fulltext as $c => $i) { if ($i == $idx_name) { $idx_cols[] = $c; unset($fulltext[$c]); } } $fulltext_back[$idx_name] = $idx_cols; $alter_table[] = " DROP INDEX `$idx_name`"; } $alter_table[] = " CHANGE `$col` `$col` $bintype $default $null"; $alter_table_back[] = " CHANGE `$col` `$col` $type CHARACTER SET $mysql_system_charset $default $null"; } } } list($charset) = explode('_',$collation); if (isset($mysql2charset[$charset])) $charset = $mysql2charset[$charset]; if ($charset != $GLOBALS['egw_setup']->system_charset) { $alter_table[] = " DEFAULT CHARACTER SET $mysql_system_charset"; } if (count($alter_table)) { $alter_table = "ALTER TABLE $table\n".implode(",\n",$alter_table); /*if ($running_standalone)*/ echo '

'.nl2br($alter_table)."

\n"; if (!$db->query($alter_table,__LINE__,__FILE__)) { echo "

SQL Error: ".nl2br($alter_table)."

\n"; echo "{$this->db->Type} Error: {$this->db->Errno} ({$this->db->Error})

\n"; echo "

continuing ...

\n"; continue; } foreach($fulltext_back as $idx_name => $idx_cols) { $alter_table_back[] = " ADD FULLTEXT `$idx_name` (`".implode('`,`',$idx_cols)."`)"; } if (count($alter_table_back)) { $alter_table_back = "ALTER TABLE $table\n".implode(",\n",$alter_table_back); /*if ($running_standalone)*/ echo '

'.nl2br($alter_table_back)."

\n"; if (!$db->query($alter_table_back,__LINE__,__FILE__)) { echo "

SQL Error: ".nl2br($alter_table_back)."

\n"; echo "{$this->db->Type} Error: {$this->db->Errno} ({$this->db->Error})

\n"; echo "

continuing ...

\n"; continue; } } ++$tables_modified; } } } if ($running_standalone) { echo "

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

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