Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#22791 closed defect (bug) (duplicate)

dbDelta triggers create table for existing tables when using multisite upgrade

Reported by: fliespl's profile fliespl Owned by:
Milestone: Priority: normal
Severity: minor Version:
Component: Upgrade/Install Keywords:
Focuses: Cc:

Description

If you are using multisite and upgrade is run on the database, it will try to create global tables for each multisite blog (triggering errors).

It's because of the line: 1533-1534 in wp-admin/includes/upgrade.php

		if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) )
			continue;

Since you put continue, "create table" will never be "unset" in the line 1679, because it had already left the loop:

unset( $cqueries[ $table ], $for_update[ $table ] );

Proposed fix:
change lines 1533-1534 from:

		if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) )
			continue;

to:

		if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) ) {
			$wpdb->suppress_errors();
			$tablefields = $wpdb->get_results("DESCRIBE {$table};");
			$wpdb->suppress_errors( false );
			if ( $tablefields )
				unset( $cqueries[ $table ], $for_update[ $table ] );
			continue;
		}

This way, if global tables don't exist they will remain in $cqueries, but if they exist, they will be unset from creation.

Change History (2)

#1 @fliespl
12 years ago

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

Duplicate of #22134.

#2 @ocean90
12 years ago

  • Keywords has-patch removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.