From 017a3e24f91cb13e34c21c9b57a965439f154cf9 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 31 May 2007 17:19:29 +0000 Subject: [PATCH] r1546: Adding convert_database_charset.php --- install/convert_database_charset.php | 146 +++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 install/convert_database_charset.php diff --git a/install/convert_database_charset.php b/install/convert_database_charset.php new file mode 100644 index 0000000..eae65d0 --- /dev/null +++ b/install/convert_database_charset.php @@ -0,0 +1,146 @@ +input_clean('step', TYPE_UINT); + +// ################################################################### + +function PrintContinue($step) +{ + global $admin; + + $admin->form_start('convert_database_charset.php', 'convert'); + $admin->form_hidden_field('step', $step); + echo "\n"; + $admin->form_end(); +} + +$admin->page_start('Convert Database Character Set'); + +// ################################################################### + +if ($bugsys->in['step'] == 0) +{ + $collation = $db->query_first("SHOW VARIABLES LIKE 'collation_database'"); + + echo '

Convert Database Character Set

'; + echo '

Earlier versions of Bugdar did not check or enforce the MySQL database character set or collation. It is recommended that the database be set at ' . TARGET . '. This script can migrate all of data from your current character set/collation of ' . $collation['Value'] . '. If you would like to convert your database to utf8, please click the link below.

'; + + echo '

Please back up your database before continuing! While this script is tested and should be safe, it is better to be cautious.

'; + + PrintContinue(1); +} + +// ################################################################### + +else if ($bugsys->in['step'] == 1) +{ + echo '

Convert Database Character Set

'; + echo '

This step changes the database\'s character set.

'; + + require './includes/config.php'; + $db->query("ALTER DATABASE $database COLLATE " . TARGET); + + PrintContinue(2); +} + +// ################################################################### + +else if ($bugsys->in['step'] == 2) +{ + echo '

Convert Table Character Set

'; + echo '

This converts each table\'s character set and collation.

'; + + $admin->table_start(); + $admin->table_head('Table Conversion'); + $admin->table_column_head(array('Table Name', 'Result')); + + $tables = $db->query("SHOW TABLES"); + while ($table = $db->fetch_array($tables, false)) + { + $db->query("ALTER TABLE $table[0] COLLATE " . TARGET); + $admin->row_text($table[0], 'Good'); + } + + $admin->table_end(); + + PrintContinue(3); +} + +// ################################################################### + +else if ($bugsys->in['step'] == 3) +{ + echo '

Convert Table Columns

'; + echo '

This converts all the table columns that are stored with a character set.

'; + + $admin->table_start(); + $admin->table_head('Column Conversion'); + $admin->table_column_head(array('Table', 'Column')); + + $tables = $db->query("SHOW TABLES"); + while ($table = $db->fetch_array($tables, false)) + { + $columns = $db->query("SHOW FULL COLUMNS FROM $table[0]"); + while ($col = $db->fetch_array($columns)) + { + if (!is_null($col['Collation'])) + { + $db->query("ALTER TABLE $table[0] MODIFY $col[Field] $col[Type] COLLATE " . TARGET); + $admin->row_text($table[0], $col['Field']); + } + } + } + + $admin->table_end(); + + PrintContinue(4); +} + +// ################################################################### + +else if ($bugsys->in['step'] == 4) +{ + echo '

Conversion Complete

'; + echo '

Your database has now been converted to the ' . TARGET . ' collation. Congratulations. Please check that everything is operating correctly.

'; +} + +// ################################################################### + +$admin->page_end(); + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.43.5