Skip to content

Commit db8bebf

Browse files
authored
Merge branch 'main' into copilot/add-wp-db-users-command
2 parents 421a9a4 + a959fd3 commit db8bebf

File tree

10 files changed

+100
-8
lines changed

10 files changed

+100
-8
lines changed

.github/workflows/code-quality.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
branches:
77
- main
88
- master
9+
schedule:
10+
- cron: '17 2 * * *' # Run every day on a seemly random time.
911

1012
jobs:
1113
code-quality:

.github/workflows/copilot-setup-steps.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ jobs:
1717

1818
steps:
1919
- name: Checkout code
20-
uses: actions/checkout@v6
20+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2121

2222
- name: Check existence of composer.json file
2323
id: check_composer_file
24-
uses: andstor/file-existence-action@v3
24+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
2525
with:
2626
files: "composer.json"
2727

2828
- name: Set up PHP environment
2929
if: steps.check_composer_file.outputs.files_exists == 'true'
30-
uses: shivammathur/setup-php@v2
30+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
3131
with:
3232
php-version: 'latest'
3333
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: Install Composer dependencies & cache dependencies
4040
if: steps.check_composer_file.outputs.files_exists == 'true'
41-
uses: ramsey/composer-install@v3
41+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3
4242
env:
4343
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4444
with:

.github/workflows/issue-triage.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ name: Issue and PR Triage
1313
required: false
1414
type: string
1515

16+
permissions:
17+
issues: write
18+
pull-requests: write
19+
actions: write
20+
contents: read
21+
models: read
22+
1623
jobs:
1724
issue-triage:
1825
uses: wp-cli/.github/.github/workflows/reusable-issue-triage.yml@main

.github/workflows/regenerate-readme.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
- "features/**"
1111
- "README.md"
1212

13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
1317
jobs:
1418
regenerate-readme:
1519
uses: wp-cli/.github/.github/workflows/reusable-regenerate-readme.yml@main

.github/workflows/welcome-new-contributors.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
- main
88
- master
99

10+
permissions:
11+
pull-requests: write
12+
1013
jobs:
1114
welcome:
1215
uses: wp-cli/.github/.github/workflows/reusable-welcome-new-contributors.yml@main

.typos.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[default]
2+
extend-ignore-re = [
3+
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$",
4+
"(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on",
5+
"(#|//)\\s*spellchecker:ignore-next-line\\n.*"
6+
]

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ Opens a MySQL console using credentials from wp-config.php
303303
wp db cli [--database=<database>] [--default-character-set=<character-set>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--defaults]
304304
~~~
305305

306+
**Alias:** `connect`
307+
306308
**OPTIONS**
307309

308310
[--database=<database>]
@@ -432,6 +434,8 @@ Exports the database to a file or to STDOUT.
432434
wp db export [<file>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--tables=<tables>] [--exclude_tables=<tables>] [--include-tablespaces] [--porcelain] [--add-drop-table] [--defaults]
433435
~~~
434436

437+
**Alias:** `dump`
438+
435439
Runs `mysqldump` utility using `DB_HOST`, `DB_NAME`, `DB_USER` and
436440
`DB_PASSWORD` database credentials specified in wp-config.php. Accepts any valid `mysqldump` flags.
437441

features/db-check.feature

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ Feature: Check the database
1313
Success: Database checked.
1414
"""
1515

16+
Scenario: db check with --quiet flag should only show errors
17+
Given a WP install
18+
19+
When I run `wp db check --quiet`
20+
Then STDOUT should be empty
21+
22+
Scenario: db check can explicitly pass --silent to mysqlcheck
23+
Given a WP install
24+
25+
When I run `wp db check --silent`
26+
Then STDOUT should not contain:
27+
"""
28+
wp_cli_test.wp_users
29+
"""
30+
And STDOUT should contain:
31+
"""
32+
Success: Database checked.
33+
"""
34+
1635
Scenario: Run db check with MySQL defaults to check the database
1736
Given a WP install
1837

features/db.feature

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@ Feature: Perform database operations
185185
"""
186186
And STDOUT should not be empty
187187
188+
Scenario: db repair with --quiet flag should only show errors
189+
Given a WP install
190+
191+
When I run `wp db repair --quiet`
192+
Then STDOUT should not contain:
193+
"""
194+
error
195+
"""
196+
197+
Scenario: db repair can explicitly pass --silent to mysqlcheck
198+
Given a WP install
199+
200+
When I run `wp db repair --silent`
201+
Then STDOUT should not contain:
202+
"""
203+
error
204+
"""
205+
And STDOUT should contain:
206+
"""
207+
Success: Database repaired.
208+
"""
209+
188210
Scenario: DB Query
189211
Given a WP install
190212
@@ -334,7 +356,7 @@ Feature: Perform database operations
334356
"""
335357
Query succeeded. Rows affected: 1
336358
"""
337-
359+
338360
When I run `wp db query "SELECT * FROM wp_users WHERE ID = 1"`
339361
Then STDOUT should not contain:
340362
"""

src/DB_Command.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use WP_CLI\Formatter;
44
use WP_CLI\Utils;
5+
use cli\table\Column;
56

67
/**
78
* Performs basic database operations using credentials stored in wp-config.php.
@@ -259,6 +260,12 @@ public function check( $_, $assoc_args ) {
259260
WP_CLI::debug( "Running shell command: {$command}", 'db' );
260261

261262
$assoc_args['check'] = true;
263+
264+
// Pass --silent to mysqlcheck when in quiet mode.
265+
if ( WP_CLI::get_config( 'quiet' ) ) {
266+
$assoc_args['silent'] = true;
267+
}
268+
262269
self::run(
263270
Utils\esc_cmd( $command, DB_NAME ),
264271
$assoc_args
@@ -307,6 +314,12 @@ public function optimize( $_, $assoc_args ) {
307314
WP_CLI::debug( "Running shell command: {$command}", 'db' );
308315

309316
$assoc_args['optimize'] = true;
317+
318+
// Pass --silent to mysqlcheck when in quiet mode.
319+
if ( WP_CLI::get_config( 'quiet' ) ) {
320+
$assoc_args['silent'] = true;
321+
}
322+
310323
self::run(
311324
Utils\esc_cmd( $command, DB_NAME ),
312325
$assoc_args
@@ -355,6 +368,12 @@ public function repair( $_, $assoc_args ) {
355368
WP_CLI::debug( "Running shell command: {$command}", 'db' );
356369

357370
$assoc_args['repair'] = true;
371+
372+
// Pass --silent to mysqlcheck when in quiet mode.
373+
if ( WP_CLI::get_config( 'quiet' ) ) {
374+
$assoc_args['silent'] = true;
375+
}
376+
358377
self::run(
359378
Utils\esc_cmd( $command, DB_NAME ),
360379
$assoc_args
@@ -1142,6 +1161,12 @@ public function size( $args, $assoc_args ) {
11421161
$size_key = floor( log( (float) $row['Size'] ) / log( 1000 ) );
11431162
$sizes = [ 'B', 'KB', 'MB', 'GB', 'TB' ];
11441163

1164+
if ( is_infinite( $size_key ) ) {
1165+
$size_key = 0;
1166+
}
1167+
1168+
$size_key = (int) $size_key;
1169+
11451170
$size_format = isset( $sizes[ $size_key ] ) ? $sizes[ $size_key ] : $sizes[0];
11461171
}
11471172

@@ -1199,7 +1224,6 @@ public function size( $args, $assoc_args ) {
11991224
if ( ! empty( $size_format ) && ! $tables && ! $format && ! $human_readable && true !== $all_tables && true !== $all_tables_with_prefix ) {
12001225
WP_CLI::line( str_replace( " {$size_format_display}", '', $rows[0]['Size'] ) );
12011226
} else {
1202-
12031227
// Sort the rows by user input
12041228
if ( $orderby ) {
12051229
usort(
@@ -1220,7 +1244,8 @@ function ( $a, $b ) use ( $order, $orderby ) {
12201244

12211245
// Display the rows.
12221246
$args = [
1223-
'format' => $format,
1247+
'format' => $format,
1248+
'alignments' => [ 'Size' => Column::ALIGN_RIGHT ],
12241249
];
12251250

12261251
$formatter = new Formatter( $args, $fields );
@@ -1816,7 +1841,7 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
18161841
$required['default-character-set'] = constant( 'DB_CHARSET' );
18171842
}
18181843

1819-
// Using 'dbuser' as option name to workaround clash with WP-CLI's global WP 'user' parameter, with 'dbpass' also available for tidyness.
1844+
// Using 'dbuser' as option name to workaround clash with WP-CLI's global WP 'user' parameter, with 'dbpass' also available for tidiness.
18201845
if ( isset( $assoc_args['dbuser'] ) ) {
18211846
$required['user'] = $assoc_args['dbuser'];
18221847
unset( $assoc_args['dbuser'] );

0 commit comments

Comments
 (0)