Skip to content

Commit 7c99105

Browse files
authored
Merge branch 'main' into copilot/fix-multinetwork-update-db
2 parents 7dd1285 + 8641c45 commit 7c99105

File tree

10 files changed

+542
-53
lines changed

10 files changed

+542
-53
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

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

2222
- name: Check existence of composer.json file
2323
id: check_composer_file
@@ -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@3cf229dc2919194e9e36783941438d17239e8520 # v3
41+
uses: ramsey/composer-install@a35c6ebd3d08125aaf8852dff361e686a1a67947 # v3
4242
env:
4343
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4444
with:

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ or success message when up to date.
8888

8989

9090

91+
### wp core check-update-db
92+
93+
Checks for the need for WordPress database updates.
94+
95+
~~~
96+
wp core check-update-db [--network]
97+
~~~
98+
99+
Compares the current database version with the version required by WordPress core
100+
to determine if database updates are needed.
101+
102+
**OPTIONS**
103+
104+
[--network]
105+
Check databases for all sites on a network.
106+
107+
**EXAMPLES**
108+
109+
# Check if database update is needed
110+
$ wp core check-update-db
111+
Success: WordPress database is up to date.
112+
113+
# Check database update status for all sites on a network
114+
$ wp core check-update-db --network
115+
Success: WordPress databases are up to date on 5/5 sites.
116+
117+
118+
91119
### wp core download
92120

93121
Downloads core WordPress files.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"require": {
1515
"composer/semver": "^1.4 || ^2 || ^3",
16-
"wp-cli/wp-cli": "^2.12"
16+
"wp-cli/wp-cli": "^2.13"
1717
},
1818
"require-dev": {
1919
"wp-cli/checksum-command": "^1 || ^2",
@@ -40,6 +40,7 @@
4040
"commands": [
4141
"core",
4242
"core check-update",
43+
"core check-update-db",
4344
"core download",
4445
"core install",
4546
"core is-installed",
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Feature: Check if WordPress database update is needed
2+
3+
# This test downgrades to an older WordPress version, but the SQLite plugin requires 6.0+
4+
@require-mysql
5+
Scenario: Check if database update is needed on a single site
6+
Given a WP install
7+
And a disable_sidebar_check.php file:
8+
"""
9+
<?php
10+
WP_CLI::add_wp_hook( 'init', static function () {
11+
remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
12+
} );
13+
"""
14+
And I try `wp theme install twentytwenty --activate`
15+
And I run `wp core download --version=5.4 --force`
16+
And I run `wp option update db_version 45805 --require=disable_sidebar_check.php`
17+
18+
When I try `wp core check-update-db`
19+
Then the return code should be 1
20+
And STDOUT should contain:
21+
"""
22+
WordPress database update required from db version 45805 to 47018.
23+
"""
24+
25+
When I run `wp core update-db`
26+
Then STDOUT should contain:
27+
"""
28+
Success: WordPress database upgraded successfully from db version 45805 to 47018.
29+
"""
30+
31+
When I run `wp core check-update-db`
32+
Then STDOUT should contain:
33+
"""
34+
Success: WordPress database is up to date.
35+
"""
36+
37+
Scenario: Check if database update is needed when database is already up to date
38+
Given a WP install
39+
40+
When I run `wp core check-update-db`
41+
Then STDOUT should contain:
42+
"""
43+
Success: WordPress database is up to date.
44+
"""
45+
46+
Scenario: Check if database update is needed across network
47+
Given a WP multisite install
48+
And a disable_sidebar_check.php file:
49+
"""
50+
<?php
51+
WP_CLI::add_wp_hook( 'init', static function () {
52+
remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
53+
} );
54+
"""
55+
And I try `wp theme install twentytwenty --activate`
56+
And I run `wp core download --version=6.6 --force`
57+
And I run `wp option update db_version 57155 --require=disable_sidebar_check.php`
58+
And I run `wp site option update wpmu_upgrade_site 57155`
59+
And I run `wp site create --slug=foo`
60+
And I run `wp site create --slug=bar`
61+
And I run `wp site create --slug=burrito --porcelain`
62+
And save STDOUT as {BURRITO_ID}
63+
And I run `wp site create --slug=taco --porcelain`
64+
And save STDOUT as {TACO_ID}
65+
And I run `wp site create --slug=pizza --porcelain`
66+
And save STDOUT as {PIZZA_ID}
67+
And I run `wp site archive {BURRITO_ID}`
68+
And I run `wp site spam {TACO_ID}`
69+
And I run `wp site delete {PIZZA_ID} --yes`
70+
And I run `wp core update`
71+
72+
When I try `wp core check-update-db --network`
73+
Then the return code should be 1
74+
And STDOUT should contain:
75+
"""
76+
WordPress database update needed on 3/3 sites:
77+
"""
78+
79+
When I run `wp core update-db --network`
80+
Then STDOUT should contain:
81+
"""
82+
Success: WordPress database upgraded on 3/3 sites.
83+
"""
84+
85+
When I run `wp core check-update-db --network`
86+
Then STDOUT should contain:
87+
"""
88+
Success: WordPress databases are up to date on 3/3 sites.
89+
"""
90+
91+
Scenario: Check database update on network installation errors on single site
92+
Given a WP install
93+
94+
When I try `wp core check-update-db --network`
95+
Then STDERR should contain:
96+
"""
97+
Error: This is not a multisite installation.
98+
"""
99+
And the return code should be 1

features/core-check-update.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,19 @@ Feature: Check for more recent versions
7070
"""
7171
---
7272
"""
73+
74+
Scenario: Check update shows warning when version check API fails
75+
Given a WP install
76+
And that HTTP requests to https://api.wordpress.org/core/version-check/1.7/ will respond with:
77+
"""
78+
HTTP/1.1 500 Internal Server Error
79+
Content-Type: text/plain
80+
81+
<Error body>
82+
"""
83+
84+
When I try `wp core check-update --force-check`
85+
Then STDERR should contain:
86+
"""
87+
Warning: Failed to check for updates
88+
"""

features/core-install.feature

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -177,50 +177,21 @@ Feature: Install WordPress core
177177
"""
178178
And the return code should be 0
179179
180-
@less-than-php-7
181-
Scenario: Install WordPress with locale set to de_DE on WP < 4.0
180+
Scenario: Install WordPress with special characters in the admin password
182181
Given an empty directory
183-
And an empty cache
182+
And WP files
183+
And wp-config.php
184184
And a database
185185
186-
When I run `wp core download --version=3.7 --locale=de_DE`
187-
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
188-
And I run `echo {VERSION}`
186+
When I run `wp core install --url=localhost:8001 --title=Test --admin_user=wpcli --admin_email=wpcli@example.org --admin_password='R^^CzY;G"iZ@]H9b,' --skip-email`
189187
Then STDOUT should contain:
190-
"""
191-
3.7
192-
"""
193-
And the wp-settings.php file should exist
194-
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.tar.gz file should exist
195-
196-
When I run `wp config create --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASSWORD} --dbhost={DB_HOST} --locale=de_DE --skip-check`
197-
Then STDOUT should be:
198-
"""
199-
Success: Generated 'wp-config.php' file.
200-
"""
201-
202-
# Old versions of WP can generate wpdb database errors if the WP tables don't exist, so STDERR may or may not be empty
203-
When I try `wp core install --url=example.org --title=Test --admin_user=testadmin --admin_email=testadmin@example.com --admin_password=newpassword --locale=de_DE --skip-email`
204-
Then STDERR should contain:
205-
"""
206-
Warning: The flag --locale=de_DE is being ignored as it requires WordPress 4.0+.
207-
"""
208-
And STDOUT should contain:
209188
"""
210189
Success: WordPress installed successfully.
211190
"""
191+
And the return code should be 0
212192
213-
When I run `wp core version`
214-
Then STDOUT should contain:
215-
"""
216-
3.7
217-
"""
218-
219-
When I run `wp taxonomy list`
220-
Then STDOUT should contain:
221-
"""
222-
Kategorien
223-
"""
193+
When I run `wp user check-password wpcli 'R^^CzY;G"iZ@]H9b,' --escape-chars`
194+
Then the return code should be 0
224195
225196
# This test downgrades to an older WordPress version, but the SQLite plugin requires 6.0+
226197
@require-mysql

features/core-update.feature

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Feature: Update WordPress core
167167
When I run `wp core update`
168168
Then STDOUT should contain:
169169
"""
170-
WordPress is up to date
170+
WordPress is up to date at version
171171
"""
172172
And STDOUT should not contain:
173173
"""
@@ -420,6 +420,107 @@ Feature: Update WordPress core
420420
</div>
421421
"""
422422

423+
Scenario: Update WordPress locale without --force when version is the same
424+
Given a WP install
425+
And an empty cache
426+
427+
# Using `try` in case there are checksum warnings.
428+
When I try `wp core download --version=6.5 --locale=de_DE --force`
429+
Then STDOUT should contain:
430+
"""
431+
Success: WordPress downloaded.
432+
"""
433+
434+
When I run `wp core version --extra`
435+
Then STDOUT should contain:
436+
"""
437+
Package language: de_DE
438+
"""
439+
440+
When I run `wp core version`
441+
Then save STDOUT as {CURRENT_VERSION}
442+
443+
# Updating to the same version with a different locale should work without --force.
444+
When I run `wp core update --version={CURRENT_VERSION} --locale=en_US`
445+
Then STDOUT should contain:
446+
"""
447+
Updating to version {CURRENT_VERSION} (en_US)...
448+
"""
449+
And STDOUT should contain:
450+
"""
451+
Success: WordPress updated successfully.
452+
"""
453+
454+
When I run `wp core version --extra`
455+
Then STDOUT should contain:
456+
"""
457+
Package language: en_US
458+
"""
459+
460+
Scenario: Update WordPress locale when using --minor
461+
Given a WP install
462+
And an empty cache
463+
464+
# Using `try` in case there are checksum warnings.
465+
When I try `wp core download --version=6.5 --locale=de_DE --force`
466+
Then STDOUT should contain:
467+
"""
468+
Success: WordPress downloaded.
469+
"""
470+
471+
When I run `wp core version --extra`
472+
Then STDOUT should contain:
473+
"""
474+
Package language: de_DE
475+
"""
476+
477+
When I run `wp core update --minor --locale=en_US`
478+
Then STDOUT should contain:
479+
"""
480+
Success: WordPress updated successfully.
481+
"""
482+
483+
When I run `wp core version --extra`
484+
Then STDOUT should contain:
485+
"""
486+
Package language: en_US
487+
"""
488+
@require-php-7.0 @require-wp-6.1
489+
Scenario: Attempting to downgrade without --force shows helpful message
490+
Given a WP install
491+
492+
When I run `wp core version`
493+
Then save STDOUT as {WP_CURRENT_VERSION}
494+
495+
When I try `wp core update --version=6.0`
496+
Then STDOUT should contain:
497+
"""
498+
WordPress is up to date at version
499+
"""
500+
And STDOUT should contain:
501+
"""
502+
is older than the current version
503+
"""
504+
And STDOUT should contain:
505+
"""
506+
Use --force to update anyway
507+
"""
508+
And STDOUT should not contain:
509+
"""
510+
Success:
511+
"""
512+
And the return code should be 0
513+
514+
When I run `wp core update --version=6.0 --force`
515+
Then STDOUT should contain:
516+
"""
517+
Updating to version 6.0
518+
"""
519+
And STDOUT should contain:
520+
"""
521+
Success: WordPress updated successfully.
522+
"""
523+
423524
Scenario: Show helpful tip when update is locked
424525
Given a WP install
425526

@@ -436,4 +537,4 @@ Feature: Update WordPress core
436537
Then STDOUT should contain:
437538
"""
438539
Success:
439-
"""
540+
"""

0 commit comments

Comments
 (0)