Skip to content
Draft
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
109 changes: 109 additions & 0 deletions features/db-quiet.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
Feature: Quiet mode for database operations

Scenario: db check with --quiet flag should only show errors
Given a WP install

When I run `wp db check --quiet`
Then STDOUT should not contain:
"""
wp_cli_test.wp_users
"""
And STDOUT should be empty

Scenario: db optimize with --quiet flag should only show errors
Given a WP install

When I run `wp db optimize --quiet`
Then STDOUT should not contain:
"""
wp_cli_test.wp_users
"""
And STDOUT should be empty

Scenario: db repair with --quiet flag should only show errors
Given a WP install

When I run `wp db repair --quiet`
Then STDOUT should not contain:
"""
wp_cli_test.wp_users
"""
And STDOUT should be empty

Scenario: db check without --quiet flag should show informational messages
Given a WP install

When I run `wp db check`
Then STDOUT should contain:
"""
wp_cli_test.wp_users
"""
And STDOUT should contain:
"""
Success: Database checked.
"""

Scenario: db optimize without --quiet flag should show informational messages
Given a WP install

When I run `wp db optimize`
Then STDOUT should contain:
"""
wp_cli_test.wp_users
"""
And STDOUT should contain:
"""
Success: Database optimized.
"""

Scenario: db repair without --quiet flag should show informational messages
Given a WP install

When I run `wp db repair`
Then STDOUT should contain:
"""
wp_cli_test.wp_users
"""
And STDOUT should contain:
"""
Success: Database repaired.
"""

Scenario: db check can explicitly pass --silent to mysqlcheck
Given a WP install

When I run `wp db check --silent`
Then STDOUT should not contain:
"""
wp_cli_test.wp_users
"""
And STDOUT should contain:
"""
Success: Database checked.
"""

Scenario: db optimize can explicitly pass --silent to mysqlcheck
Given a WP install

When I run `wp db optimize --silent`
Then STDOUT should not contain:
"""
wp_cli_test.wp_users
"""
And STDOUT should contain:
"""
Success: Database optimized.
"""

Scenario: db repair can explicitly pass --silent to mysqlcheck
Given a WP install

When I run `wp db repair --silent`
Then STDOUT should not contain:
"""
wp_cli_test.wp_users
"""
And STDOUT should contain:
"""
Success: Database repaired.
"""
18 changes: 18 additions & 0 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ public function check( $_, $assoc_args ) {
WP_CLI::debug( "Running shell command: {$command}", 'db' );

$assoc_args['check'] = true;

// Pass --silent to mysqlcheck when in quiet mode.
if ( WP_CLI::get_config( 'quiet' ) ) {
$assoc_args['silent'] = true;
}

self::run(
Utils\esc_cmd( $command, DB_NAME ),
$assoc_args
Expand Down Expand Up @@ -307,6 +313,12 @@ public function optimize( $_, $assoc_args ) {
WP_CLI::debug( "Running shell command: {$command}", 'db' );

$assoc_args['optimize'] = true;

// Pass --silent to mysqlcheck when in quiet mode.
if ( WP_CLI::get_config( 'quiet' ) ) {
$assoc_args['silent'] = true;
}

self::run(
Utils\esc_cmd( $command, DB_NAME ),
$assoc_args
Expand Down Expand Up @@ -355,6 +367,12 @@ public function repair( $_, $assoc_args ) {
WP_CLI::debug( "Running shell command: {$command}", 'db' );

$assoc_args['repair'] = true;

// Pass --silent to mysqlcheck when in quiet mode.
if ( WP_CLI::get_config( 'quiet' ) ) {
$assoc_args['silent'] = true;
}

self::run(
Utils\esc_cmd( $command, DB_NAME ),
$assoc_args
Expand Down
Loading