Skip to content
Closed
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
18 changes: 18 additions & 0 deletions features/db.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ Feature: Perform database operations
When I try the previous command again
Then the return code should be 1

When I run `wp db check`
Then STDOUT should be:
"""
wp_cli_test.wp_commentmeta OK
wp_cli_test.wp_comments OK
wp_cli_test.wp_links OK
wp_cli_test.wp_options OK
wp_cli_test.wp_postmeta OK
wp_cli_test.wp_posts OK
wp_cli_test.wp_term_relationships OK
wp_cli_test.wp_term_taxonomy OK
wp_cli_test.wp_termmeta OK
wp_cli_test.wp_terms OK
wp_cli_test.wp_usermeta OK
wp_cli_test.wp_users OK
Success: Database checked.
"""

When I run `wp db optimize`
Then STDOUT should not be empty

Expand Down
23 changes: 23 additions & 0 deletions php/commands/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ public function reset( $_, $assoc_args ) {
WP_CLI::success( "Database reset." );
}

/**
* Check the database in MySQL.
*
* Runs `mysqlcheck` utility with `--check` using `DB_HOST`,
* `DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials
* specified in wp-config.php.
*
* [See docs](http://dev.mysql.com/doc/refman/5.7/en/check-table.html)
* for more details on the `CHECK TABLE` statement.
*
* ## EXAMPLES
*
* $ wp db check
* Success: Database checked.
*/
public function check() {
self::run( Utils\esc_cmd( 'mysqlcheck --no-defaults %s', DB_NAME ), array(
'check' => true,
) );

WP_CLI::success( "Database checked." );
}

/**
* Optimize the database in MySQL.
*
Expand Down