Skip to content

Commit

Permalink
fix: importing mysql db tables into mariadb/wp-env
Browse files Browse the repository at this point in the history
  • Loading branch information
lgersman committed Dec 21, 2023
1 parent bf39694 commit a1a21a8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugins/cm4all-wp-impex/inc/impex-import-extension-db-table.php
Expand Up @@ -208,6 +208,21 @@ interface DbTableImporter
function __registerDbTableImportProvider()
{
$provider = Impex::getInstance()->Import->addProvider(DbTableImporter::PROVIDER_NAME, __NAMESPACE__ . '\__DbTableImportProviderCallback');

global $wpdb;
$db_version = $wpdb->get_row('SHOW VARIABLES LIKE "version_comment"', ARRAY_A)['Value'] ?? 'MySQL';

if (stripos($db_version, 'mariadb') !== false) {
// we need to replace legacy utf8 encodings with just utf8 and the matching collation in create table statements when importing tables from a mysqldb export to mariadb
// see https://tecadmin.net/resolved-unknown-collation-utf8mb4_0900_ai_ci/
\add_filter('query', function (string $sql) {
$sql = str_replace('utf8mb4_0900_ai_ci', 'utf8_general_ci', $sql);
$sql = str_replace('utf8mb4', 'utf8', $sql);

return $sql;
});
}

return $provider;
}

Expand Down

0 comments on commit a1a21a8

Please sign in to comment.