diff --git a/utf8mb4-cli-upgrader.php b/utf8mb4-cli-upgrader.php new file mode 100644 index 0000000..c8b4b00 --- /dev/null +++ b/utf8mb4-cli-upgrader.php @@ -0,0 +1,52 @@ +get_results("SHOW TABLES"); + foreach ($mytables as $mytable) { + foreach ($mytable as $t) { + $old_collation = $wpdb->get_var("SELECT TABLE_COLLATION FROM information_schema.TABLES WHERE TABLE_NAME = '$t'"); + WP_CLI::line("Table {$t} current collation: {$old_collation}"); + + $converted = maybe_convert_table_to_utf8mb4($t); + if ($converted) { + $new_collation = $wpdb->get_var("SELECT TABLE_COLLATION FROM information_schema.TABLES WHERE TABLE_NAME = '$t'"); + WP_CLI::line("Table {$t} converted. New collation: {$new_collation}"); + } + } + } + } + } + + // Ensure WP_CLI class exists before adding the command. + if (class_exists('WP_CLI')) { + // Register our new CLI command. + WP_CLI::add_command('upgrade_utf8mb4', 'utf8mb4_Database_Upgrade'); + } + }