From 8a8ab62e9ee3e4689f30405b5e63af3337345fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Thu, 11 Aug 2016 22:37:10 +0000 Subject: [PATCH 1/3] Implement wp db check --- features/db.feature | 3 +++ php/commands/db.php | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/features/db.feature b/features/db.feature index 338cdc9358..0fb875c3cd 100644 --- a/features/db.feature +++ b/features/db.feature @@ -21,6 +21,9 @@ 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 not be empty + 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. * From 1c851b4a5984d3ee46997c25452103c353b043e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Thu, 11 Aug 2016 23:14:53 +0000 Subject: [PATCH 2/3] Improving wp db check test --- features/db.feature | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/features/db.feature b/features/db.feature index 0fb875c3cd..f350d9c709 100644 --- a/features/db.feature +++ b/features/db.feature @@ -22,7 +22,21 @@ Feature: Perform database operations Then the return code should be 1 When I run `wp db check` - Then STDOUT should not be empty + 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 + """ When I run `wp db optimize` Then STDOUT should not be empty From 62aac0c2bb5c7fef170a0959202e39db51563ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Fri, 12 Aug 2016 00:32:42 +0000 Subject: [PATCH 3/3] Add missing success message to wp db check test --- features/db.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/features/db.feature b/features/db.feature index f350d9c709..dc520222ea 100644 --- a/features/db.feature +++ b/features/db.feature @@ -36,6 +36,7 @@ Feature: Perform database operations 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`