diff --git a/features/db.feature b/features/db.feature index 338cdc9358..dc520222ea 100644 --- a/features/db.feature +++ b/features/db.feature @@ -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 diff --git a/php/commands/db.php b/php/commands/db.php index 6dff55ea8c..4de397231f 100644 --- a/php/commands/db.php +++ b/php/commands/db.php @@ -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. *