From af36459713b47e8f9d2f7559d3c11b71231019c2 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Sun, 5 Nov 2017 05:54:12 -0800 Subject: [PATCH] Use new `after_wp_config_load` early invoke to run `wp db *` commands --- src/DB_Command.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/DB_Command.php b/src/DB_Command.php index c748faa06..75138a433 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -21,6 +21,8 @@ * * # Execute a SQL query stored in a file. * $ wp db query < debug.sql + * + * @when after_wp_config_load */ class DB_Command extends WP_CLI_Command { @@ -469,6 +471,8 @@ public function import( $args, $assoc_args ) { * # Export only tables for a single site * $ wp db export --tables=$(wp db tables --url=sub.example.com --format=csv) * Success: Exported to wordpress_dbase.sql + * + * @when after_wp_load */ public function tables( $args, $assoc_args ) { @@ -568,12 +572,11 @@ public function tables( $args, $assoc_args ) { * * $ wp db size --size_format=mb * 6 + * + * @when after_wp_load */ public function size( $args, $assoc_args ) { - // Avoid a constant redefinition in wp-config. - @WP_CLI::get_runner()-> load_wordpress(); - global $wpdb; $format = WP_CLI\Utils\get_flag_value( $assoc_args, 'format' ); @@ -668,11 +671,10 @@ public function size( $args, $assoc_args ) { * * $ wp db prefix * wp_ + * + * @when after_wp_load */ public function prefix() { - // Avoid a constant redefinition in wp-config. - @WP_CLI::get_runner()->load_wordpress(); - global $wpdb; WP_CLI::log( $wpdb->prefix ); @@ -799,15 +801,13 @@ public function prefix() { * ... * Success: Found 99146 matches in 10.752s (10.559s searching). Searched 12 tables, 53 columns, 1358907 rows. 1 table skipped: wp_term_relationships. * + * @when after_wp_load */ public function search( $args, $assoc_args ) { global $wpdb; $start_run_time = microtime( true ); - // Avoid a constant redefinition in wp-config. - @WP_CLI::get_runner()->load_wordpress(); - $search = array_shift( $args ); $before_context = \WP_CLI\Utils\get_flag_value( $assoc_args, 'before_context', 40 );