Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions features/core-update-db.feature
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ Feature: Update core's database
{UPDATE_VERSION}
"""

Scenario: Update db respects current network in multinetwork setup
Given a WP multisite install
And a disable_sidebar_check.php file:
"""
<?php
WP_CLI::add_wp_hook( 'init', static function () {
remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
} );
"""
And I try `wp theme install twentytwenty --activate`

# Verify that network ID is determined correctly
When I run `wp eval "echo defined('SITE_ID_CURRENT_SITE') ? SITE_ID_CURRENT_SITE : 'not defined';"`
Then STDOUT should contain:
"""
1
"""

Scenario: Ensure update-db sets WP_INSTALLING constant
Given a WP install
And a before.php file:
Expand Down
16 changes: 16 additions & 0 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,11 @@ public function update( $args, $assoc_args ) {
* WordPress database upgraded successfully from db version 35700 to 29630 on example.com/
* Success: WordPress database upgraded on 123/123 sites.
*
* # Update databases for all sites on a specific network in a multinetwork install.
* $ wp core update-db --network --url=network2.example.com
* WordPress database upgraded successfully from db version 35700 to 29630 on network2.example.com/
* Success: WordPress database upgraded on 50/50 sites.
*
* @subcommand update-db
*
* @param string[] $args Positional arguments. Unused.
Expand All @@ -1315,9 +1320,20 @@ public function update_db( $args, $assoc_args ) {
}

if ( $network ) {
// Determine the network ID to update
// In multinetwork setups, use the current network (determined by --url parameter)
$network_id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : null;
if ( null === $network_id && function_exists( 'get_current_network_id' ) ) {
$network_id = get_current_network_id();
}
if ( null === $network_id ) {
$network_id = 1; // Default to primary network
}

$iterator_args = [
'table' => $wpdb->blogs,
'where' => [
'site_id' => $network_id,
'spam' => 0,
'deleted' => 0,
'archived' => 0,
Expand Down
Loading