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
19 changes: 19 additions & 0 deletions features/db-check.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ Feature: Check the database
Success: Database checked.
"""

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

When I run `wp db check --quiet`
Then STDOUT should be empty

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: Run db check with MySQL defaults to check the database
Given a WP install

Expand Down
47 changes: 46 additions & 1 deletion features/db.feature
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,51 @@ Feature: Perform database operations
"""
And STDOUT should not 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:
"""
error
"""


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:
"""
error
"""
And STDOUT should contain:
"""
Success: Database optimized.
"""

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:
"""
error
"""

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:
"""
error
"""
And STDOUT should contain:
"""
Success: Database repaired.
"""

Scenario: DB Query
Given a WP install

Expand Down Expand Up @@ -334,7 +379,7 @@ Feature: Perform database operations
"""
Query succeeded. Rows affected: 1
"""

When I run `wp db query "SELECT * FROM wp_users WHERE ID = 1"`
Then STDOUT should not contain:
"""
Expand Down
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