Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#22791 closed defect (bug) (duplicate)

dbDelta triggers create table for existing tables when using multisite upgrade

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

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
14 years ago

  • Resolution → duplicate
  • Status new → closed

Duplicate of #22134.

#2 @ocean90
14 years ago

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