1
1
<?php
2
2
3
3
use WP_CLI \Formatter ;
4
- use \ WP_CLI \Utils ;
4
+ use WP_CLI \Utils ;
5
5
6
6
/**
7
7
* Performs basic database operations using credentials stored in wp-config.php.
@@ -158,7 +158,7 @@ public function clean( $_, $assoc_args ) {
158
158
159
159
$ mysql_args = self ::get_dbuser_dbpass_args ( $ assoc_args );
160
160
161
- $ tables = WP_CLI \ Utils \wp_get_table_names (
161
+ $ tables = Utils \wp_get_table_names (
162
162
array (),
163
163
array ( 'all-tables-with-prefix ' )
164
164
);
@@ -374,7 +374,7 @@ public function cli( $args, $assoc_args ) {
374
374
public function query ( $ args , $ assoc_args ) {
375
375
$ assoc_args ['database ' ] = DB_NAME ;
376
376
377
- // The query might come from STDIN
377
+ // The query might come from STDIN.
378
378
if ( ! empty ( $ args ) ) {
379
379
$ assoc_args ['execute ' ] = $ args [0 ];
380
380
}
@@ -471,7 +471,7 @@ public function export( $args, $assoc_args ) {
471
471
472
472
}
473
473
$ stdout = ( '- ' === $ result_file );
474
- $ porcelain = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'porcelain ' );
474
+ $ porcelain = Utils \get_flag_value ( $ assoc_args , 'porcelain ' );
475
475
476
476
// Bail if both porcelain and STDOUT are set.
477
477
if ( $ stdout && $ porcelain ) {
@@ -502,7 +502,7 @@ public function export( $args, $assoc_args ) {
502
502
}
503
503
}
504
504
505
- $ exclude_tables = WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'exclude_tables ' );
505
+ $ exclude_tables = Utils \get_flag_value ( $ assoc_args , 'exclude_tables ' );
506
506
if ( isset ( $ exclude_tables ) ) {
507
507
$ tables = explode ( ', ' , trim ( $ assoc_args ['exclude_tables ' ], ', ' ) );
508
508
unset( $ assoc_args ['exclude_tables ' ] );
@@ -575,7 +575,7 @@ public function import( $args, $assoc_args ) {
575
575
WP_CLI ::error ( sprintf ( 'Import file missing or not readable: %s ' , $ result_file ) );
576
576
}
577
577
578
- $ query = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'skip-optimization ' )
578
+ $ query = Utils \get_flag_value ( $ assoc_args , 'skip-optimization ' )
579
579
? 'SOURCE %s; '
580
580
: 'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %s; COMMIT; ' ;
581
581
@@ -642,14 +642,14 @@ public function import( $args, $assoc_args ) {
642
642
*/
643
643
public function tables ( $ args , $ assoc_args ) {
644
644
645
- $ format = WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'format ' );
645
+ $ format = Utils \get_flag_value ( $ assoc_args , 'format ' );
646
646
unset( $ assoc_args ['format ' ] );
647
647
648
648
if ( empty ( $ args ) && empty ( $ assoc_args ) ) {
649
649
$ assoc_args ['scope ' ] = 'all ' ;
650
650
}
651
651
652
- $ tables = WP_CLI \ Utils \wp_get_table_names ( $ args , $ assoc_args );
652
+ $ tables = Utils \wp_get_table_names ( $ args , $ assoc_args );
653
653
654
654
if ( 'csv ' === $ format ) {
655
655
WP_CLI ::line ( implode ( ', ' , $ tables ) );
@@ -774,13 +774,13 @@ public function size( $args, $assoc_args ) {
774
774
775
775
global $ wpdb ;
776
776
777
- $ format = WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'format ' );
778
- $ size_format = WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'size_format ' );
779
- $ human_readable = WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'human-readable ' , false );
780
- $ tables = WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'tables ' );
777
+ $ format = Utils \get_flag_value ( $ assoc_args , 'format ' );
778
+ $ size_format = Utils \get_flag_value ( $ assoc_args , 'size_format ' );
779
+ $ human_readable = Utils \get_flag_value ( $ assoc_args , 'human-readable ' , false );
780
+ $ tables = Utils \get_flag_value ( $ assoc_args , 'tables ' );
781
781
$ tables = ! empty ( $ tables );
782
- $ all_tables = WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'all-tables ' );
783
- $ all_tables_with_prefix = WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'all-tables-with-prefix ' );
782
+ $ all_tables = Utils \get_flag_value ( $ assoc_args , 'all-tables ' );
783
+ $ all_tables_with_prefix = Utils \get_flag_value ( $ assoc_args , 'all-tables-with-prefix ' );
784
784
785
785
if ( ! is_null ( $ size_format ) && $ human_readable ) {
786
786
WP_CLI ::error ( 'Cannot use --size_format and --human-readable arguments at the same time. ' );
@@ -804,7 +804,7 @@ public function size( $args, $assoc_args ) {
804
804
if ( $ tables || $ all_tables || $ all_tables_with_prefix ) {
805
805
806
806
// Add all of the table sizes
807
- foreach ( WP_CLI \ Utils \wp_get_table_names ( $ args , $ assoc_args ) as $ table_name ) {
807
+ foreach ( Utils \wp_get_table_names ( $ args , $ assoc_args ) as $ table_name ) {
808
808
809
809
// Get the table size.
810
810
$ table_bytes = $ wpdb ->get_var (
@@ -840,7 +840,7 @@ public function size( $args, $assoc_args ) {
840
840
841
841
if ( ! empty ( $ size_format ) || $ human_readable ) {
842
842
foreach ( $ rows as $ index => $ row ) {
843
- // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
843
+ // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Backfilling WP native constants.
844
844
if ( ! defined ( 'KB_IN_BYTES ' ) ) {
845
845
define ( 'KB_IN_BYTES ' , 1024 );
846
846
}
@@ -862,7 +862,7 @@ public function size( $args, $assoc_args ) {
862
862
$ size_format = isset ( $ sizes [ $ size_key ] ) ? $ sizes [ $ size_key ] : $ sizes [0 ];
863
863
}
864
864
865
- // Display the database size as a number.
865
+ // Display the database size as a number.
866
866
switch ( $ size_format ) {
867
867
case 'TB ' :
868
868
$ divisor = pow ( 1000 , 4 );
@@ -1086,17 +1086,17 @@ public function search( $args, $assoc_args ) {
1086
1086
1087
1087
$ search = array_shift ( $ args );
1088
1088
1089
- $ before_context = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'before_context ' , 40 );
1089
+ $ before_context = Utils \get_flag_value ( $ assoc_args , 'before_context ' , 40 );
1090
1090
$ before_context = '' === $ before_context ? $ before_context : (int ) $ before_context ;
1091
1091
1092
- $ after_context = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'after_context ' , 40 );
1092
+ $ after_context = Utils \get_flag_value ( $ assoc_args , 'after_context ' , 40 );
1093
1093
$ after_context = '' === $ after_context ? $ after_context : (int ) $ after_context ;
1094
1094
1095
- $ regex = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'regex ' , false );
1095
+ $ regex = Utils \get_flag_value ( $ assoc_args , 'regex ' , false );
1096
1096
if ( false !== $ regex ) {
1097
- $ regex_flags = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'regex-flags ' , false );
1097
+ $ regex_flags = Utils \get_flag_value ( $ assoc_args , 'regex-flags ' , false );
1098
1098
$ default_regex_delimiter = false ;
1099
- $ regex_delimiter = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'regex-delimiter ' , '' );
1099
+ $ regex_delimiter = Utils \get_flag_value ( $ assoc_args , 'regex-delimiter ' , '' );
1100
1100
if ( '' === $ regex_delimiter ) {
1101
1101
$ regex_delimiter = chr ( 1 );
1102
1102
$ default_regex_delimiter = true ;
@@ -1112,10 +1112,10 @@ public function search( $args, $assoc_args ) {
1112
1112
)
1113
1113
);
1114
1114
1115
- $ table_column_once = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'table_column_once ' , false );
1116
- $ one_line = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'one_line ' , false );
1117
- $ matches_only = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'matches_only ' , false );
1118
- $ stats = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'stats ' , false );
1115
+ $ table_column_once = Utils \get_flag_value ( $ assoc_args , 'table_column_once ' , false );
1116
+ $ one_line = Utils \get_flag_value ( $ assoc_args , 'one_line ' , false );
1117
+ $ matches_only = Utils \get_flag_value ( $ assoc_args , 'matches_only ' , false );
1118
+ $ stats = Utils \get_flag_value ( $ assoc_args , 'stats ' , false );
1119
1119
1120
1120
$ column_count = 0 ;
1121
1121
$ row_count = 0 ;
@@ -1148,7 +1148,7 @@ public function search( $args, $assoc_args ) {
1148
1148
$ encoding = 'UTF-8 ' ;
1149
1149
}
1150
1150
1151
- $ tables = WP_CLI \ Utils \wp_get_table_names ( $ args , $ assoc_args );
1151
+ $ tables = Utils \wp_get_table_names ( $ args , $ assoc_args );
1152
1152
1153
1153
$ start_search_time = microtime ( true );
1154
1154
@@ -1338,12 +1338,12 @@ public function search( $args, $assoc_args ) {
1338
1338
public function columns ( $ args , $ assoc_args ) {
1339
1339
global $ wpdb ;
1340
1340
1341
- $ format = WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'format ' );
1341
+ $ format = Utils \get_flag_value ( $ assoc_args , 'format ' );
1342
1342
1343
- WP_CLI \ Utils \wp_get_table_names ( array ( $ args [0 ] ), array () );
1343
+ Utils \wp_get_table_names ( array ( $ args [0 ] ), array () );
1344
1344
1345
1345
$ columns = $ wpdb ->get_results (
1346
- // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Asserted to be a valid table name through wp_get_table_names.
1346
+ // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Asserted to be a valid table name through wp_get_table_names.
1347
1347
'SHOW COLUMNS FROM ' . $ args [0 ]
1348
1348
);
1349
1349
@@ -1406,11 +1406,11 @@ private static function run( $cmd, $assoc_args = array(), $descriptors = null )
1406
1406
*/
1407
1407
private static function get_dbuser_dbpass_args ( $ assoc_args ) {
1408
1408
$ mysql_args = array ();
1409
- $ dbuser = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'dbuser ' );
1409
+ $ dbuser = Utils \get_flag_value ( $ assoc_args , 'dbuser ' );
1410
1410
if ( null !== $ dbuser ) {
1411
1411
$ mysql_args ['dbuser ' ] = $ dbuser ;
1412
1412
}
1413
- $ dbpass = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'dbpass ' );
1413
+ $ dbpass = Utils \get_flag_value ( $ assoc_args , 'dbpass ' );
1414
1414
if ( null !== $ dbpass ) {
1415
1415
$ mysql_args ['dbpass ' ] = $ dbpass ;
1416
1416
}
@@ -1508,7 +1508,7 @@ function ( $v ) {
1508
1508
$ color_codes_regex = '/^(?:%[ ' . $ color_codes . '])*$/ ' ;
1509
1509
1510
1510
foreach ( array_keys ( $ colors ) as $ color_col ) {
1511
- $ col_color_flag = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , $ color_col . '_color ' , false );
1511
+ $ col_color_flag = Utils \get_flag_value ( $ assoc_args , $ color_col . '_color ' , false );
1512
1512
if ( false !== $ col_color_flag ) {
1513
1513
if ( ! preg_match ( $ color_codes_regex , $ col_color_flag , $ matches ) ) {
1514
1514
WP_CLI ::warning ( "Unrecognized percent color code ' $ col_color_flag' for ' {$ color_col }_color'. " );
0 commit comments