Skip to content

Commit 154723e

Browse files
authored
Bail early when check/dump commands are missing (#339)
1 parent 6356e15 commit 154723e

3 files changed

Lines changed: 33 additions & 13 deletions

File tree

‎features/db-check.feature‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ Feature: Check the database
154154
Given a WP install
155155

156156
When I try `wp db check --defaults --debug`
157-
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) %s#
157+
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysqlcheck|mariadb-check) %s#
158158

159159
When I try `wp db check --debug`
160-
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#
160+
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysqlcheck|mariadb-check) --no-defaults %s#
161161

162162
When I try `wp db check --no-defaults --debug`
163-
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#
163+
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysqlcheck|mariadb-check) --no-defaults %s#
164164

165165
@require-mysql-or-mariadb
166166
Scenario: Empty DB credentials should not cause empty parameter errors

‎features/db-export.feature‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ Feature: Export a WordPress database
140140
Given a WP install
141141

142142
When I try `wp db export --defaults --debug`
143-
Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump)#
143+
Then STDERR should match #Debug \(db\): Running initial shell command: /([^/]+/)+(mysqldump|mariadb-dump)#
144144

145145
When I try `wp db export --debug`
146-
Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump) --no-defaults#
146+
Then STDERR should match #Debug \(db\): Running initial shell command: /([^/]+/)+(mysqldump|mariadb-dump) --no-defaults#
147147

148148
When I try `wp db export --no-defaults --debug`
149-
Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump) --no-defaults#
149+
Then STDERR should match #Debug \(db\): Running initial shell command: /([^/]+/)+(mysqldump|mariadb-dump) --no-defaults#
150150

151151
@skip-sqlite
152152
@skip-windows

‎src/DB_Command.php‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,14 @@ public function check( $_, $assoc_args ) {
286286
return;
287287
}
288288

289+
$check_command = Utils\get_sql_check_command();
290+
if ( '' === $check_command ) {
291+
WP_CLI::error( 'The mysqlcheck or mariadb-check binary is not available.' );
292+
}
293+
289294
$command = sprintf(
290-
'/usr/bin/env %s%s %s',
291-
Utils\get_sql_check_command(),
295+
'%s%s %s',
296+
$check_command,
292297
$this->get_defaults_flag_string( $assoc_args ),
293298
'%s'
294299
);
@@ -347,9 +352,14 @@ public function optimize( $_, $assoc_args ) {
347352
return;
348353
}
349354

355+
$check_command = Utils\get_sql_check_command();
356+
if ( '' === $check_command ) {
357+
WP_CLI::error( 'The mysqlcheck or mariadb-check binary is not available.' );
358+
}
359+
350360
$command = sprintf(
351-
'/usr/bin/env %s%s %s',
352-
Utils\get_sql_check_command(),
361+
'%s%s %s',
362+
$check_command,
353363
$this->get_defaults_flag_string( $assoc_args ),
354364
'%s'
355365
);
@@ -408,9 +418,14 @@ public function repair( $_, $assoc_args ) {
408418
return;
409419
}
410420

421+
$check_command = Utils\get_sql_check_command();
422+
if ( '' === $check_command ) {
423+
WP_CLI::error( 'The mysqlcheck or mariadb-check binary is not available.' );
424+
}
425+
411426
$command = sprintf(
412-
'/usr/bin/env %s%s %s',
413-
Utils\get_sql_check_command(),
427+
'%s%s %s',
428+
$check_command,
414429
$this->get_defaults_flag_string( $assoc_args ),
415430
'%s'
416431
);
@@ -756,7 +771,12 @@ public function export( $args, $assoc_args ) {
756771
$assoc_args['result-file'] = $result_file;
757772
}
758773

759-
$mysqldump_binary = Utils\force_env_on_nix_systems( Utils\get_sql_dump_command() );
774+
$dump_command = Utils\get_sql_dump_command();
775+
if ( '' === $dump_command ) {
776+
WP_CLI::error( 'The mysqldump or mariadb-dump binary is not available.' );
777+
}
778+
779+
$mysqldump_binary = $dump_command;
760780

761781
$support_column_statistics = $this->command_supports_option( $mysqldump_binary, 'column-statistics' );
762782

0 commit comments

Comments
 (0)