Skip to content

Commit fe80523

Browse files
Copilotswissspidy
andcommitted
Fix multinetwork support in update-db --network command
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 <[email protected]>
1 parent f1c9d05 commit fe80523

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Core_Command.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,11 @@ public function update( $args, $assoc_args ) {
12961296
* WordPress database upgraded successfully from db version 35700 to 29630 on example.com/
12971297
* Success: WordPress database upgraded on 123/123 sites.
12981298
*
1299+
* # Update databases for all sites on a specific network in a multinetwork install.
1300+
* $ wp core update-db --network --url=network2.example.com
1301+
* WordPress database upgraded successfully from db version 35700 to 29630 on network2.example.com/
1302+
* Success: WordPress database upgraded on 50/50 sites.
1303+
*
12991304
* @subcommand update-db
13001305
*
13011306
* @param string[] $args Positional arguments. Unused.
@@ -1315,9 +1320,20 @@ public function update_db( $args, $assoc_args ) {
13151320
}
13161321

13171322
if ( $network ) {
1323+
// Determine the network ID to update
1324+
// In multinetwork setups, use the current network (determined by --url parameter)
1325+
$network_id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : null;
1326+
if ( null === $network_id && function_exists( 'get_current_network_id' ) ) {
1327+
$network_id = get_current_network_id();
1328+
}
1329+
if ( null === $network_id ) {
1330+
$network_id = 1; // Default to primary network
1331+
}
1332+
13181333
$iterator_args = [
13191334
'table' => $wpdb->blogs,
13201335
'where' => [
1336+
'site_id' => $network_id,
13211337
'spam' => 0,
13221338
'deleted' => 0,
13231339
'archived' => 0,

0 commit comments

Comments
 (0)