From f6adcd3c68d13012a5f90e6db4d334ea9b9fb2c8 Mon Sep 17 00:00:00 2001 From: Jason Cosper Date: Wed, 19 Jul 2023 22:43:19 +0000 Subject: [PATCH] Add plugin file --- utf8mb4-cli-upgrader.php | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 utf8mb4-cli-upgrader.php 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'); + } + }