Skip to content

Conversation

Copy link

Copilot AI commented Nov 7, 2025

Description

In multinetwork WordPress installations, wp core update-db --network queries all blogs without filtering by site_id, causing it to only update the first network regardless of the --url parameter.

Changes

Core Logic (src/Core_Command.php)

  • Detect current network ID from SITE_ID_CURRENT_SITE constant (set by --url), falling back to get_current_network_id(), then network ID 1
  • Add site_id filter to TableIterator WHERE clause to scope blogs to current network
  • Optimize metadata update to directly use $network_id instead of collecting and deduplicating site IDs
  • Add documentation example for multinetwork usage

Test Coverage (features/core-update-db.feature)

  • Add comprehensive test that downgrades WordPress and database versions, creates multiple sites, verifies network ID detection, executes the update-db command, and validates successful upgrade of all sites in the network

Usage

# Update sites in specific network
wp core update-db --network --url=network2.example.com

# Update primary network (backward compatible)
wp core update-db --network

Backward Compatibility

Standard multisite installations (single network) maintain existing behavior as network ID defaults to 1.


Fixes #198

Original prompt

This section details on the original issue you should resolve

<issue_title>wp core update-db --network only updates the first network for "multinetwork" install</issue_title>
<issue_description>Hello! I've been trying something but doesn't work fine.

I have a WordPress MultiNetwork installed (for a client) and I've been trying to do this command wp core update-db like a network, but doesn't update everything.

wp core update-db --network --path=/web/example.com/

This updates the "first" multisite, as expected.

But, there are 2 networks, and inside each one, there are some subsites. If I execute

wp core update-db --network --url="network1.com" --path=/web/example.com/

Or any other "url" it always executes the first multisite in the network.

I think there are 2 possibles solutions there. The first one (I think that will the best one) is to run

wp core update-db --network --path=/web/example.com/

and check all the subsites (whatever network they are). I think maybe check all the sites in the database active or not (because archived sites should also update the database tables).

The other case may be to use the --url parameter with the main hostname (in a multinetwork you have hostnames and then subfolders), so if you use the --url parameter, check al the sites for this network.</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber Thanks for the report, @javiercasares !

The other case may be to use the --url parameter with the main hostname (in a multinetwork you have hostnames and then subfolders), so if you use the --url parameter, check al the sites for this network.

I think this approach probably makes more sense.

Out of curiosity, how does WordPress core handle this for the web?</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 7, 2025
Copilot AI and others added 2 commits November 7, 2025 22:23
Add site_id filtering to ensure only sites from the current network are updated when using --network flag. This allows proper operation in multinetwork WordPress installations when combined with --url parameter.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Add a simple test to verify that SITE_ID_CURRENT_SITE is properly defined in multisite installations, which is used by the update-db command to filter sites by network.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix wp core update-db for multiple networks Fix wp core update-db --network to respect network ID in multinetwork installations Nov 7, 2025
Copilot AI requested a review from swissspidy November 7, 2025 22:28
Copilot finished work on behalf of swissspidy November 7, 2025 22:28
Include WordPress downgrade, database version downgrade, site creation, and verification of the actual update-db command execution and success.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot finished work on behalf of swissspidy November 8, 2025 08:49
Copilot AI requested a review from swissspidy November 8, 2025 08:49
@codecov
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Core_Command.php 77.77% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy requested a review from Copilot November 8, 2025 09:41

This comment was marked as resolved.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Since all blogs are filtered by site_id = network_id, there's no need to collect and deduplicate site_ids. Directly use network_id for the metadata update.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot finished work on behalf of swissspidy November 8, 2025 10:18
@swissspidy swissspidy marked this pull request as ready for review November 10, 2025 14:55
@swissspidy swissspidy requested a review from a team as a code owner November 10, 2025 14:55
@wojsmol
Copy link
Contributor

wojsmol commented Nov 10, 2025

@swissspidy We have a fatal php error in tests

Fatal error: Uncaught Error: Failed opening required '/home/runner/work/core-command/core-command/vendor/behat/gherkin/src/../../../i18n.php' (include_path='.:/usr/share/php') in /home/runner/work/core-command/core-command/vendor/behat/gherkin/src/Keywords/CachedArrayKeywords.php:35

https://github.com/wp-cli/core-command/actions/runs/19191674343/job/54867112573?pr=302

@swissspidy
Copy link
Member

@wojsmol You're looking at a previous run. I just fixed that error in my recent commit, all tests are passing now (except for PHP nightly, but that's a different story)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants