Skip to content

Commit aef1158

Browse files
Copilotswissspidy
andcommitted
Extract MariaDB detection into helper method with basename check
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 30a9efa commit aef1158

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Context/FeatureContext.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,16 @@ private function set_cache_dir(): void {
11651165
$this->variables['CACHE_DIR'] = $path;
11661166
}
11671167

1168+
/**
1169+
* Check if the given binary path is for MariaDB.
1170+
*
1171+
* @param string $binary_path Path to the database binary.
1172+
* @return bool True if MariaDB, false otherwise.
1173+
*/
1174+
private static function is_mariadb( $binary_path ) {
1175+
return false !== strpos( basename( $binary_path ), 'mariadb' );
1176+
}
1177+
11681178
/**
11691179
* Run a MySQL command with `$db_settings`.
11701180
*
@@ -1203,7 +1213,7 @@ public function create_db(): void {
12031213
}
12041214

12051215
$dbname = self::$db_settings['dbname'];
1206-
$ssl_flag = ( false !== strpos( self::$mysql_binary, 'mariadb' ) ) ? ' --ssl-verify-server-cert' : '';
1216+
$ssl_flag = self::is_mariadb( self::$mysql_binary ) ? ' --ssl-verify-server-cert' : '';
12071217
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "CREATE DATABASE IF NOT EXISTS $dbname" ] );
12081218
}
12091219

@@ -1215,7 +1225,7 @@ public function test_connection(): void {
12151225
return;
12161226
}
12171227

1218-
$ssl_flag = ( false !== strpos( self::$mysql_binary, 'mariadb' ) ) ? ' --ssl-verify-server-cert' : '';
1228+
$ssl_flag = self::is_mariadb( self::$mysql_binary ) ? ' --ssl-verify-server-cert' : '';
12191229
$sql_result = self::run_sql(
12201230
self::$mysql_binary . ' --no-defaults' . $ssl_flag,
12211231
[
@@ -1244,7 +1254,7 @@ public function drop_db(): void {
12441254
return;
12451255
}
12461256
$dbname = self::$db_settings['dbname'];
1247-
$ssl_flag = ( false !== strpos( self::$mysql_binary, 'mariadb' ) ) ? ' --ssl-verify-server-cert' : '';
1257+
$ssl_flag = self::is_mariadb( self::$mysql_binary ) ? ' --ssl-verify-server-cert' : '';
12481258
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "DROP DATABASE IF EXISTS $dbname" ] );
12491259
}
12501260

@@ -1482,7 +1492,7 @@ public function install_wp( $subdir = '', $version = '' ): void {
14821492
if ( 'sqlite' === self::$db_type ) {
14831493
copy( "{$install_cache_path}.sqlite", "$run_dir/wp-content/database/.ht.sqlite" );
14841494
} else {
1485-
$ssl_flag = ( false !== strpos( self::$mysql_binary, 'mariadb' ) ) ? ' --ssl-verify-server-cert' : '';
1495+
$ssl_flag = self::is_mariadb( self::$mysql_binary ) ? ' --ssl-verify-server-cert' : '';
14861496
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "source {$install_cache_path}.sql" ], true /*add_database*/ );
14871497
}
14881498
} else {
@@ -1496,7 +1506,7 @@ public function install_wp( $subdir = '', $version = '' ): void {
14961506
$mysqldump_binary = Utils\get_sql_dump_command();
14971507
$mysqldump_binary = Utils\force_env_on_nix_systems( $mysqldump_binary );
14981508
$support_column_statistics = exec( "{$mysqldump_binary} --help | grep 'column-statistics'" );
1499-
$ssl_flag = ( false !== strpos( $mysqldump_binary, 'mariadb' ) ) ? ' --ssl-verify-server-cert' : '';
1509+
$ssl_flag = self::is_mariadb( $mysqldump_binary ) ? ' --ssl-verify-server-cert' : '';
15001510
$command = "{$mysqldump_binary} --no-defaults{$ssl_flag} --no-tablespaces";
15011511
if ( $support_column_statistics ) {
15021512
$command .= ' --skip-column-statistics';

0 commit comments

Comments
 (0)