Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions features/db-export.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 15 additions & 1 deletion src/DB_Command.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use WP_CLI\Formatter;
use WP_CLI\Process;
use WP_CLI\Utils;
use cli\table\Column;

Expand Down Expand Up @@ -747,7 +748,7 @@ public function export( $args, $assoc_args ) {

$mysqldump_binary = Utils\force_env_on_nix_systems( Utils\get_sql_dump_command() );

$support_column_statistics = exec( $mysqldump_binary . ' --help | grep "column-statistics"' );
$support_column_statistics = $this->command_supports_option( $mysqldump_binary, 'column-statistics' );

/*
* In case that `--default-character-set` is not given and `DB_CHARSET` is `utf8`,
Expand Down Expand Up @@ -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.
*
Expand Down
Loading