Skip to content

Fixes #118: On multisite-convert, don't assume site_id is 1#122

Merged
schlessera merged 5 commits intowp-cli:masterfrom
andyzito:118-site-id
Oct 8, 2019
Merged

Fixes #118: On multisite-convert, don't assume site_id is 1#122
schlessera merged 5 commits intowp-cli:masterfrom
andyzito:118-site-id

Conversation

@andyzito
Copy link
Contributor

In the populate_network function, which is used by core multisite-convert, I observe the following code (line 1007 of wp-admin/includes/schema.php at v4.9.9):

if ( 1 == $network_id ) {
	$wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) );
	$network_id = $wpdb->insert_id;
} else {
	$wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'id' => $network_id ) );
}

My understanding of the code in Core_Command.php is that multisite-convert is invoking populate_network(), and passing 1 as the site id ($network_id). As you can see, the WP core code then sets the network_id equal to the result of the INSERT query against wp_site. In most cases, this would be 1; however, if one has configured auto_increment_increment -- as is standard practice for database clusters -- then the wp_site table will store the site as id 4, and the code will generate the rest of the data using that same id.

From the perspective of core-command, this is mostly not a concern. However, it does appear that the constant SITE_ID_CURRENT_SITE is hardcoded with value 1. This produces an inconsistency between the config file and the database which is less than ideal. The solution is simple -- store the actual site_id/network_id and use that instead of a hardcoded 1. The only downside is that it means one extra database query (functions like get_main_network_id() appear to be accessing some kind of cache, or perhaps are falling back to default, and only return 1).

@andyzito andyzito requested a review from a team as a code owner April 25, 2019 17:18
@schlessera schlessera added the command:core-multisite-convert Related to 'core multisite-convert' command label May 2, 2019
@andyzito
Copy link
Contributor Author

andyzito commented May 2, 2019

I made two changes to the code:

  1. Use a direct DB call to get the site id. This should have been in my original pull request, but I missed committing the final changes I had made locally. I found that none of the multisite functions succeeded in obtaining the actual site id. Incidentally, this also fixes your first change request.

  2. Escaped the string as you suggested.

@schlessera
Copy link
Member

@azito122 Are you still interested in working on this?

Andrew Zito and others added 3 commits August 27, 2019 15:49
Co-Authored-By: Alain Schlesser <alain.schlesser@gmail.com>
Co-Authored-By: Alain Schlesser <alain.schlesser@gmail.com>
@andyzito
Copy link
Contributor Author

@schlessera Yes. Apologies for going radio silent. I've made the last changes you requested and rebased.

@schlessera schlessera added this to the 2.0.7 milestone Oct 8, 2019
@schlessera schlessera merged commit 6532da4 into wp-cli:master Oct 8, 2019
@schlessera
Copy link
Member

Thanks for the PR, @azito122 !

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

Labels

command:core-multisite-convert Related to 'core multisite-convert' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants