From efb14d9a0f1f64e19f49e0f50ed5152e8f0f4e85 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:22:49 +0000 Subject: [PATCH 1/8] Initial plan From 2ec53de7fe39828477eeb1cac238ad70837f7918 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:27:06 +0000 Subject: [PATCH 2/8] Initial plan for wp core check-update-db command Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6a3fe712..4cf56905 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "composer/semver": "^1.4 || ^2 || ^3", + "composer/semver": "^3", "wp-cli/wp-cli": "^2.12" }, "require-dev": { From 246f8a0ba41fb4abc9182e5cdb334439528abc2d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:28:41 +0000 Subject: [PATCH 3/8] Add wp core check-update-db command Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- composer.json | 1 + features/core-check-update-db.feature | 100 +++++++++++++++++++++++++ src/Core_Command.php | 102 ++++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 features/core-check-update-db.feature diff --git a/composer.json b/composer.json index 4cf56905..cabea7d5 100644 --- a/composer.json +++ b/composer.json @@ -40,6 +40,7 @@ "commands": [ "core", "core check-update", + "core check-update-db", "core download", "core install", "core is-installed", diff --git a/features/core-check-update-db.feature b/features/core-check-update-db.feature new file mode 100644 index 00000000..a7f8560e --- /dev/null +++ b/features/core-check-update-db.feature @@ -0,0 +1,100 @@ +Feature: Check if WordPress database update is needed + + # This test downgrades to an older WordPress version, but the SQLite plugin requires 6.0+ + @require-mysql + Scenario: Check if database update is needed on a single site + Given a WP install + And a disable_sidebar_check.php file: + """ + $wpdb->blogs, + 'where' => [ + 'spam' => 0, + 'deleted' => 0, + 'archived' => 0, + ], + ]; + $it = new TableIterator( $iterator_args ); + $total = 0; + $needs_update = 0; + $sites_needing_update = []; + + /** + * @var object{site_id: int, domain: string, path: string} $blog + */ + foreach ( $it as $blog ) { + ++$total; + $url = $blog->domain . $blog->path; + $cmd = "--url={$url} core check-update-db"; + + /** + * @var object{stdout: string, stderr: string, return_code: int} $process + */ + $process = WP_CLI::runcommand( + $cmd, + [ + 'return' => 'all', + 'exit_error' => false, + ] + ); + // If return code is 1, it means update is needed + if ( 1 === (int) $process->return_code ) { + ++$needs_update; + $sites_needing_update[] = $url; + } + } + + if ( $needs_update > 0 ) { + WP_CLI::log( "WordPress database update needed on {$needs_update}/{$total} sites:" ); + foreach ( $sites_needing_update as $site_url ) { + WP_CLI::log( " - {$site_url}" ); + } + WP_CLI::halt( 1 ); + } else { + WP_CLI::success( "WordPress databases are up to date on {$total}/{$total} sites." ); + } + } else { + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; + + /** + * @var string $wp_current_db_version + */ + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Replacing WP Core behavior is the goal here. + $wp_current_db_version = __get_option( 'db_version' ); + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Replacing WP Core behavior is the goal here. + $wp_current_db_version = (int) $wp_current_db_version; + + if ( $wp_db_version !== $wp_current_db_version ) { + WP_CLI::log( "WordPress database update required from db version {$wp_current_db_version} to {$wp_db_version}." ); + WP_CLI::halt( 1 ); + } else { + WP_CLI::success( 'WordPress database is up to date.' ); + } + } + } + /** * Runs the WordPress database update procedure. * From 05f81d2c78c8ee3e2e0ee25d44fd3185f0b1742d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:30:15 +0000 Subject: [PATCH 4/8] Update README with check-update-db documentation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 4e2be2c1..78b02dce 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,34 @@ or success message when up to date. +### wp core check-update-db + +Checks for the need for WordPress database updates. + +~~~ +wp core check-update-db [--network] +~~~ + +Compares the current database version with the version required by WordPress core +to determine if database updates are needed. + +**OPTIONS** + + [--network] + Check databases for all sites on a network. + +**EXAMPLES** + + # Check if database update is needed + $ wp core check-update-db + Success: WordPress database is up to date. + + # Check database update status for all sites on a network + $ wp core check-update-db --network + Success: WordPress databases are up to date on 5/5 sites. + + + ### wp core download Downloads core WordPress files. From 2fdce40aa33188db07be0c820e113fb6b79e55d1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:55:26 +0000 Subject: [PATCH 5/8] Address PR feedback: revert README.md and fix composer.json - Revert README.md changes (file is auto-generated) - Restore composer/semver version range to "^1.4 || ^2 || ^3" Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- README.md | 28 ---------------------------- composer.json | 2 +- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/README.md b/README.md index 78b02dce..4e2be2c1 100644 --- a/README.md +++ b/README.md @@ -88,34 +88,6 @@ or success message when up to date. -### wp core check-update-db - -Checks for the need for WordPress database updates. - -~~~ -wp core check-update-db [--network] -~~~ - -Compares the current database version with the version required by WordPress core -to determine if database updates are needed. - -**OPTIONS** - - [--network] - Check databases for all sites on a network. - -**EXAMPLES** - - # Check if database update is needed - $ wp core check-update-db - Success: WordPress database is up to date. - - # Check database update status for all sites on a network - $ wp core check-update-db --network - Success: WordPress databases are up to date on 5/5 sites. - - - ### wp core download Downloads core WordPress files. diff --git a/composer.json b/composer.json index cabea7d5..7cfe8726 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "composer/semver": "^3", + "composer/semver": "^1.4 || ^2 || ^3", "wp-cli/wp-cli": "^2.12" }, "require-dev": { From e5aef83e069f7c478a0a30408e2def1185d08f6e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:58:06 +0000 Subject: [PATCH 6/8] Fix code formatting: align variable assignments properly Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Core_Command.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Core_Command.php b/src/Core_Command.php index 8f5d86d6..64391cbb 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -1287,9 +1287,9 @@ public function check_update_db( $args, $assoc_args ) { 'archived' => 0, ], ]; - $it = new TableIterator( $iterator_args ); - $total = 0; - $needs_update = 0; + $it = new TableIterator( $iterator_args ); + $total = 0; + $needs_update = 0; $sites_needing_update = []; /** From 5ade271a4f853a9638821676457c8c9e072d0137 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 2 Nov 2025 10:47:56 +0100 Subject: [PATCH 7/8] Lint fix --- src/Core_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core_Command.php b/src/Core_Command.php index 64391cbb..47f4eb7c 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -1279,7 +1279,7 @@ public function check_update_db( $args, $assoc_args ) { } if ( $network ) { - $iterator_args = [ + $iterator_args = [ 'table' => $wpdb->blogs, 'where' => [ 'spam' => 0, From 3ee4a3ef40469cbfb1cabe8877915a0d0435c11d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 2 Nov 2025 10:48:00 +0100 Subject: [PATCH 8/8] Fix test --- features/core-check-update-db.feature | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/features/core-check-update-db.feature b/features/core-check-update-db.feature index a7f8560e..b8e3bd41 100644 --- a/features/core-check-update-db.feature +++ b/features/core-check-update-db.feature @@ -43,8 +43,6 @@ Feature: Check if WordPress database update is needed Success: WordPress database is up to date. """ - # This test downgrades to an older WordPress version, but the SQLite plugin requires 6.0+ - @require-mysql Scenario: Check if database update is needed across network Given a WP multisite install And a disable_sidebar_check.php file: @@ -55,9 +53,9 @@ Feature: Check if WordPress database update is needed } ); """ And I try `wp theme install twentytwenty --activate` - And I run `wp core download --version=5.4 --force` - And I run `wp option update db_version 45805 --require=disable_sidebar_check.php` - And I run `wp site option update wpmu_upgrade_site 45805` + And I run `wp core download --version=6.6 --force` + And I run `wp option update db_version 57155 --require=disable_sidebar_check.php` + And I run `wp site option update wpmu_upgrade_site 57155` And I run `wp site create --slug=foo` And I run `wp site create --slug=bar` And I run `wp site create --slug=burrito --porcelain` @@ -69,6 +67,7 @@ Feature: Check if WordPress database update is needed And I run `wp site archive {BURRITO_ID}` And I run `wp site spam {TACO_ID}` And I run `wp site delete {PIZZA_ID} --yes` + And I run `wp core update` When I try `wp core check-update-db --network` Then the return code should be 1