Make WordPress Core

Opened 15 years ago

Closed 13 years ago

Last modified 13 years ago

#12028 closed defect (bug) (fixed)

wpmu_create_blog() breaks with multiple use

Reported by: wpmuguru's profile wpmuguru Owned by:
Milestone: 3.3 Priority: high
Severity: normal Version:
Component: Multisite Keywords: has-patch
Focuses: Cc:

Description

MU Trac Ticket: http://trac.mu.wordpress.org/ticket/394

When using wpmu_create_blog() in wpmu-functions.php it will only work once. If called additional times the blog will be added to the wp_blogs table but its tables will not be created, resulting in an invalid state. This is caused by $wp_queries being set in-line in upgrade-schema.php while it must be updated before the second call to wpmu_create_blog(). This is solved by moving the initialization of $wp_queries into a function and calling it just before the tables are created (diff file attached).

Attachments (5)

wpmu-create-blog.patch (1.1 KB) - added by jpotkanski 15 years ago.
Patch for wpmu-functions.php
wpmu-create-blog.2.patch (1.1 KB) - added by jpotkanski 15 years ago.
Patch for wpmu-functions.php
12028.diff (2.6 KB) - added by ryan 13 years ago.
12028.2.diff (11.2 KB) - added by ryan 13 years ago.
12028.3.diff (13.4 KB) - added by ryan 13 years ago.

Download all attachments as: .zip

Change History (21)

#1 @wpmuguru
15 years ago

  • Milestone changed from Unassigned to Future Release

@jpotkanski
15 years ago

Patch for wpmu-functions.php

@jpotkanski
15 years ago

Patch for wpmu-functions.php

#2 @jpotkanski
15 years ago

I reviewed the original patch, which was a significant architecture change. Our patch can be use in the interim as a workable hack.

#3 @hakre
14 years ago

Related: #16913

Version 0, edited 14 years ago by hakre (next)

#4 @westi
14 years ago

  • Cc westi added
  • Keywords needs-patch added
  • Priority changed from normal to high

Neither of the attached patches is a good idea.

Better to wrap the query generation in a function so it can be called more than once and preserve the setting of the global.

#5 @zaneselvans
13 years ago

  • Cc zane@… added

I think I ran into this same issue recently when attempting to create new blogs in a network installation. I don't know why $wp_queries wasn't getting updated to reflect the new blog_id and table prefixes... the values inside $wpdb were correct. I ended up temporarily creating a wrapper function around a copy of the table creation statements from schema.php so I could get the new blogs set up, but it wasn't something I wanted to leave that way. Notes from the experience are visible in the multi-site support forum: https://wordpress.org/support/topic/db-tables-for-new-subdomain-site-fail-to-get-created?replies=29

@ryan
13 years ago

#6 @ryan
13 years ago

  • Milestone changed from Future Release to 3.3

@ryan
13 years ago

#7 @ryan
13 years ago

Renamed the function to wp_get_db_schema() per IRC discussion. Added a scope arg which is very similar to the one for wpdb::tables(). Grouped table SQL by scope. Changed install_blog() to pass a scope of 'blog' so that it no longer uselessly and dangerously sends user and usermeta tables through dbDelta() for every blog created.

#8 @wpmuguru
13 years ago

I didn't test, but looks good.

#9 @wpmuguru
13 years ago

  • Keywords has-patch added; needs-patch removed

@ryan
13 years ago

#10 @ryan
13 years ago

Renames WP_NETWORK_ADMIN_PAGE to WP_INSTALLING_NETWORK and uses that to reliably determine if multisite in wp_get_db_schema(). This allows more exactly copying the wpdb:tables() API. Switched to a switch as seen in tables() for readability.

#11 @nacin
13 years ago

A quick grep of the plugins directory reveals 1588 references to $charset_collate. While many of these are surely going to be plugin-defined local variables, I found it specifically globalized in 3 different plugins. I imagine a number may also be using it in procedural, globally scoped code.

#12 @nacin
13 years ago

dbDelta()'s repetitive statements could probably be simplified to:

if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms' ), true ) )
    $queries = wp_get_db_schema( $queries );

#13 @ryan
13 years ago

In [18899]:

Introduce wp_get_db_schema() for rerieving the various flavors of the WP db schema. Eliminates need to use global. Allows multiple calls to wpmu_create_blog(). see #12028

#14 @ryan
13 years ago

The commit incorporates nacin's last two comments.

#15 @ryan
13 years ago

  • Resolution set to fixed
  • Status changed from new to closed

#16 @dd32
13 years ago

In [18986]:

Fix Undefined Variable Notices when no charset/collate is set for $wpdb. See #12028

Note: See TracTickets for help on using tickets.