From 290516ad410991961f0b8d924dd86109a9aedea3 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 30 Jul 2026 09:06:52 +0200 Subject: [PATCH] Bail early when check/dump commands are missing --- features/db-check.feature | 6 +++--- features/db-export.feature | 6 +++--- src/DB_Command.php | 34 +++++++++++++++++++++++++++------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/features/db-check.feature b/features/db-check.feature index 53c73d1a..744219ea 100644 --- a/features/db-check.feature +++ b/features/db-check.feature @@ -154,13 +154,13 @@ Feature: Check the database Given a WP install When I try `wp db check --defaults --debug` - Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) %s# + Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysqlcheck|mariadb-check) %s# When I try `wp db check --debug` - Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s# + Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysqlcheck|mariadb-check) --no-defaults %s# When I try `wp db check --no-defaults --debug` - Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s# + Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysqlcheck|mariadb-check) --no-defaults %s# @require-mysql-or-mariadb Scenario: Empty DB credentials should not cause empty parameter errors diff --git a/features/db-export.feature b/features/db-export.feature index de212a13..6303f608 100644 --- a/features/db-export.feature +++ b/features/db-export.feature @@ -140,13 +140,13 @@ Feature: Export a WordPress database Given a WP install When I try `wp db export --defaults --debug` - Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump)# + Then STDERR should match #Debug \(db\): Running initial shell command: /([^/]+/)+(mysqldump|mariadb-dump)# When I try `wp db export --debug` - Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump) --no-defaults# + Then STDERR should match #Debug \(db\): Running initial shell command: /([^/]+/)+(mysqldump|mariadb-dump) --no-defaults# When I try `wp db export --no-defaults --debug` - Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump) --no-defaults# + Then STDERR should match #Debug \(db\): Running initial shell command: /([^/]+/)+(mysqldump|mariadb-dump) --no-defaults# @skip-sqlite @skip-windows diff --git a/src/DB_Command.php b/src/DB_Command.php index 123122ac..b6bb1376 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -286,9 +286,14 @@ public function check( $_, $assoc_args ) { return; } + $check_command = Utils\get_sql_check_command(); + if ( '' === $check_command ) { + WP_CLI::error( 'The mysqlcheck or mariadb-check binary is not available.' ); + } + $command = sprintf( - '/usr/bin/env %s%s %s', - Utils\get_sql_check_command(), + '%s%s %s', + $check_command, $this->get_defaults_flag_string( $assoc_args ), '%s' ); @@ -347,9 +352,14 @@ public function optimize( $_, $assoc_args ) { return; } + $check_command = Utils\get_sql_check_command(); + if ( '' === $check_command ) { + WP_CLI::error( 'The mysqlcheck or mariadb-check binary is not available.' ); + } + $command = sprintf( - '/usr/bin/env %s%s %s', - Utils\get_sql_check_command(), + '%s%s %s', + $check_command, $this->get_defaults_flag_string( $assoc_args ), '%s' ); @@ -408,9 +418,14 @@ public function repair( $_, $assoc_args ) { return; } + $check_command = Utils\get_sql_check_command(); + if ( '' === $check_command ) { + WP_CLI::error( 'The mysqlcheck or mariadb-check binary is not available.' ); + } + $command = sprintf( - '/usr/bin/env %s%s %s', - Utils\get_sql_check_command(), + '%s%s %s', + $check_command, $this->get_defaults_flag_string( $assoc_args ), '%s' ); @@ -756,7 +771,12 @@ public function export( $args, $assoc_args ) { $assoc_args['result-file'] = $result_file; } - $mysqldump_binary = Utils\force_env_on_nix_systems( Utils\get_sql_dump_command() ); + $dump_command = Utils\get_sql_dump_command(); + if ( '' === $dump_command ) { + WP_CLI::error( 'The mysqldump or mariadb-dump binary is not available.' ); + } + + $mysqldump_binary = $dump_command; $support_column_statistics = $this->command_supports_option( $mysqldump_binary, 'column-statistics' );