diff --git a/features/db-export.feature b/features/db-export.feature index 7635ffa9..de212a13 100644 --- a/features/db-export.feature +++ b/features/db-export.feature @@ -147,3 +147,16 @@ Feature: Export a WordPress database 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# + + @skip-sqlite + @skip-windows + Scenario: Export database when PHP exec() is disabled + Given a WP install + + When I try `{INVOKE_WP_CLI_WITH_PHP_ARGS--ddisable_functions=exec} db export wp_cli_test.sql --porcelain` + Then the return code should be 0 + And STDOUT should contain: + """ + wp_cli_test.sql + """ + And the wp_cli_test.sql file should exist diff --git a/src/DB_Command.php b/src/DB_Command.php index 03b578af..75309042 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -1,6 +1,7 @@ command_supports_option( $mysqldump_binary, 'column-statistics' ); /* * In case that `--default-character-set` is not given and `DB_CHARSET` is `utf8`, @@ -859,6 +860,19 @@ private function get_posts_table_charset( $assoc_args ) { return $stdout; } + /** + * Check whether a shell command advertises support for a specific option in `--help`. + * + * @param string $command Base shell command to inspect. + * @param string $option Option name to look for. + * @return bool Whether the option is listed in help output. + */ + private function command_supports_option( $command, $option ) { + $result = Process::create( "{$command} --help" )->run(); + + return false !== strpos( $result->stdout . $result->stderr, $option ); + } + /** * Imports a database from a file or from STDIN. *