Skip to content

Commit aaa3187

Browse files
Copilotswissspidy
andauthored
Fix MariaDB 11.4+ warnings with --no-defaults flag (#297)
* Initial plan * Add --ssl-verify-server-cert flag to MySQL commands with --no-defaults Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Add SSL flag only for MariaDB, not MySQL Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Extract MariaDB detection into helper method with basename check Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Improve documentation for is_mariadb() helper method Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Use db_type variable instead of binary path to detect MariaDB Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * inline --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent e4b8b0c commit aaa3187

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/Context/FeatureContext.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,8 @@ public function __construct() {
834834
if ( getenv( 'WP_CLI_TEST_DBTYPE' ) ) {
835835
$this->variables['DB_TYPE'] = getenv( 'WP_CLI_TEST_DBTYPE' );
836836
} else {
837-
$this->variables['DB_TYPE'] = 'mysql';
837+
// Auto-detect database type if not explicitly set
838+
$this->variables['DB_TYPE'] = Utils\get_db_type();
838839
}
839840

840841
if ( getenv( 'MYSQL_TCP_PORT' ) ) {
@@ -1202,8 +1203,9 @@ public function create_db(): void {
12021203
return;
12031204
}
12041205

1205-
$dbname = self::$db_settings['dbname'];
1206-
self::run_sql( self::$mysql_binary . ' --no-defaults', [ 'execute' => "CREATE DATABASE IF NOT EXISTS $dbname" ] );
1206+
$dbname = self::$db_settings['dbname'];
1207+
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
1208+
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "CREATE DATABASE IF NOT EXISTS $dbname" ] );
12071209
}
12081210

12091211
/**
@@ -1214,8 +1216,9 @@ public function test_connection(): void {
12141216
return;
12151217
}
12161218

1219+
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
12171220
$sql_result = self::run_sql(
1218-
self::$mysql_binary . ' --no-defaults',
1221+
self::$mysql_binary . ' --no-defaults' . $ssl_flag,
12191222
[
12201223
'execute' => 'SELECT 1',
12211224
'send_to_shell' => false,
@@ -1241,8 +1244,9 @@ public function drop_db(): void {
12411244
if ( 'sqlite' === self::$db_type ) {
12421245
return;
12431246
}
1244-
$dbname = self::$db_settings['dbname'];
1245-
self::run_sql( self::$mysql_binary . ' --no-defaults', [ 'execute' => "DROP DATABASE IF EXISTS $dbname" ] );
1247+
$dbname = self::$db_settings['dbname'];
1248+
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
1249+
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "DROP DATABASE IF EXISTS $dbname" ] );
12461250
}
12471251

12481252
/**
@@ -1479,7 +1483,8 @@ public function install_wp( $subdir = '', $version = '' ): void {
14791483
if ( 'sqlite' === self::$db_type ) {
14801484
copy( "{$install_cache_path}.sqlite", "$run_dir/wp-content/database/.ht.sqlite" );
14811485
} else {
1482-
self::run_sql( self::$mysql_binary . ' --no-defaults', [ 'execute' => "source {$install_cache_path}.sql" ], true /*add_database*/ );
1486+
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
1487+
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "source {$install_cache_path}.sql" ], true /*add_database*/ );
14831488
}
14841489
} else {
14851490
$this->proc( 'wp core install', $install_args, $subdir )->run_check();
@@ -1492,7 +1497,8 @@ public function install_wp( $subdir = '', $version = '' ): void {
14921497
$mysqldump_binary = Utils\get_sql_dump_command();
14931498
$mysqldump_binary = Utils\force_env_on_nix_systems( $mysqldump_binary );
14941499
$support_column_statistics = exec( "{$mysqldump_binary} --help | grep 'column-statistics'" );
1495-
$command = "{$mysqldump_binary} --no-defaults --no-tablespaces";
1500+
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
1501+
$command = "{$mysqldump_binary} --no-defaults{$ssl_flag} --no-tablespaces";
14961502
if ( $support_column_statistics ) {
14971503
$command .= ' --skip-column-statistics';
14981504
}

0 commit comments

Comments
 (0)