r1546: Adding convert_database_charset.php
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 31 May 2007 17:19:29 +0000 (17:19 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 31 May 2007 17:19:29 +0000 (17:19 +0000)
install/convert_database_charset.php [new file with mode: 0644]

diff --git a/install/convert_database_charset.php b/install/convert_database_charset.php
new file mode 100644 (file)
index 0000000..eae65d0
--- /dev/null
@@ -0,0 +1,146 @@
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # Bugdar [#]version[#]
+|| # Copyright ©2002-[#]year[#] Blue Static
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+define('SVN', '$Id$');
+
+chdir('../admin/');
+require_once('./global.php');
+
+define('ISSO_PRINTER_NO_NAVIGATION', 1);
+
+// you can change what you want to conver to here
+define('TARGET', 'utf8_general_ci');
+
+$bugsys->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<input type=\"submit\" value=\"  Continue &#8594;  \" name=\"__submit__\" />";
+       $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 '<h1>Convert Database Character Set</h1>';
+       echo '<p>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 <strong>' . TARGET . '</strong>. This script can migrate all of data from your current character set/collation of <strong>' . $collation['Value'] . '</strong>. If you would like to convert your database to utf8, please click the link below.</p>';
+       
+       echo '<h3>Please back up your database before continuing! While this script is tested and should be safe, it is better to be cautious.</h3>';
+       
+       PrintContinue(1);
+}
+
+// ###################################################################
+
+else if ($bugsys->in['step'] == 1)
+{
+       echo '<h1>Convert Database Character Set</h1>';
+       echo '<p>This step changes the database\'s character set.</p>';
+       
+       require './includes/config.php';
+       $db->query("ALTER DATABASE $database COLLATE " . TARGET);
+       
+       PrintContinue(2);
+}
+
+// ###################################################################
+
+else if ($bugsys->in['step'] == 2)
+{
+       echo '<h1>Convert Table Character Set</h1>';
+       echo '<p>This converts each table\'s character set and collation.</p>';
+       
+       $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 '<h1>Convert Table Columns</h1>';
+       echo '<p>This converts all the table columns that are stored with a character set.</p>';
+       
+       $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 '<h1>Conversion Complete</h1>';
+       echo '<p>Your database has now been converted to the <strong>' . TARGET . '</strong> collation. Congratulations. Please check that everything is operating correctly.</p>';
+}
+
+// ###################################################################
+
+$admin->page_end();
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file