Skip to content

Commit 7121cfd

Browse files
authored
Merge pull request #57 from wp-cli/15-after-wp-config-load
Use new `after_wp_config_load` early invoke to run `wp db *` commands
2 parents 1379a28 + af36459 commit 7121cfd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/DB_Command.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*
2222
* # Execute a SQL query stored in a file.
2323
* $ wp db query < debug.sql
24+
*
25+
* @when after_wp_config_load
2426
*/
2527
class DB_Command extends WP_CLI_Command {
2628

@@ -469,6 +471,8 @@ public function import( $args, $assoc_args ) {
469471
* # Export only tables for a single site
470472
* $ wp db export --tables=$(wp db tables --url=sub.example.com --format=csv)
471473
* Success: Exported to wordpress_dbase.sql
474+
*
475+
* @when after_wp_load
472476
*/
473477
public function tables( $args, $assoc_args ) {
474478

@@ -568,12 +572,11 @@ public function tables( $args, $assoc_args ) {
568572
*
569573
* $ wp db size --size_format=mb
570574
* 6
575+
*
576+
* @when after_wp_load
571577
*/
572578
public function size( $args, $assoc_args ) {
573579

574-
// Avoid a constant redefinition in wp-config.
575-
@WP_CLI::get_runner()-> load_wordpress();
576-
577580
global $wpdb;
578581

579582
$format = WP_CLI\Utils\get_flag_value( $assoc_args, 'format' );
@@ -668,11 +671,10 @@ public function size( $args, $assoc_args ) {
668671
*
669672
* $ wp db prefix
670673
* wp_
674+
*
675+
* @when after_wp_load
671676
*/
672677
public function prefix() {
673-
// Avoid a constant redefinition in wp-config.
674-
@WP_CLI::get_runner()->load_wordpress();
675-
676678
global $wpdb;
677679

678680
WP_CLI::log( $wpdb->prefix );
@@ -799,15 +801,13 @@ public function prefix() {
799801
* ...
800802
* Success: Found 99146 matches in 10.752s (10.559s searching). Searched 12 tables, 53 columns, 1358907 rows. 1 table skipped: wp_term_relationships.
801803
*
804+
* @when after_wp_load
802805
*/
803806
public function search( $args, $assoc_args ) {
804807
global $wpdb;
805808

806809
$start_run_time = microtime( true );
807810

808-
// Avoid a constant redefinition in wp-config.
809-
@WP_CLI::get_runner()->load_wordpress();
810-
811811
$search = array_shift( $args );
812812

813813
$before_context = \WP_CLI\Utils\get_flag_value( $assoc_args, 'before_context', 40 );

0 commit comments

Comments
 (0)