Have dbDelta() loop through tables it knows about, rather than loop through a potentially expensive and definitely unnecessary SHOW TABLES. fixes #17998.
git-svn-id: http://svn.automattic.com/wordpress/trunk@19040 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7a3fc7d36c
commit
870d7860fd
|
@ -1459,21 +1459,24 @@ function dbDelta( $queries = '', $execute = true ) {
|
||||||
$cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
|
$cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
|
||||||
$iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
|
$iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
|
||||||
|
|
||||||
// Check to see which tables and fields exist
|
|
||||||
if ($tables = $wpdb->get_col('SHOW TABLES;')) {
|
|
||||||
// For every table in the database
|
|
||||||
$global_tables = $wpdb->tables( 'global' );
|
$global_tables = $wpdb->tables( 'global' );
|
||||||
foreach ($tables as $table) {
|
foreach ( $cqueries as $table => $qry ) {
|
||||||
// Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.
|
// Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.
|
||||||
if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) )
|
if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If a table query exists for the database table...
|
// Fetch the table column structure from the database
|
||||||
if ( array_key_exists(strtolower($table), $cqueries) ) {
|
$wpdb->suppress_errors();
|
||||||
|
$tablefields = $wpdb->get_results("DESCRIBE {$table};");
|
||||||
|
$wpdb->suppress_errors( false );
|
||||||
|
|
||||||
|
if ( ! $tablefields )
|
||||||
|
continue;
|
||||||
|
|
||||||
// Clear the field and index arrays
|
// Clear the field and index arrays
|
||||||
$cfields = $indices = array();
|
$cfields = $indices = array();
|
||||||
// Get all of the field names in the query from between the parens
|
// Get all of the field names in the query from between the parens
|
||||||
preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2);
|
preg_match("|\((.*)\)|ms", $qry, $match2);
|
||||||
$qryline = trim($match2[1]);
|
$qryline = trim($match2[1]);
|
||||||
|
|
||||||
// Separate field lines into an array
|
// Separate field lines into an array
|
||||||
|
@ -1508,9 +1511,6 @@ function dbDelta( $queries = '', $execute = true ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the table column structure from the database
|
|
||||||
$tablefields = $wpdb->get_results("DESCRIBE {$table};");
|
|
||||||
|
|
||||||
// For every field in the table
|
// For every field in the table
|
||||||
foreach ($tablefields as $tablefield) {
|
foreach ($tablefields as $tablefield) {
|
||||||
// If the table field exists in the field array...
|
// If the table field exists in the field array...
|
||||||
|
@ -1608,12 +1608,7 @@ function dbDelta( $queries = '', $execute = true ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the original table creation query from processing
|
// Remove the original table creation query from processing
|
||||||
unset($cqueries[strtolower($table)]);
|
unset( $cqueries[ $table ], $for_update[ $table ] );
|
||||||
unset($for_update[strtolower($table)]);
|
|
||||||
} else {
|
|
||||||
// This table exists in the database, but not in the creation queries?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$allqueries = array_merge($cqueries, $iqueries);
|
$allqueries = array_merge($cqueries, $iqueries);
|
||||||
|
|
Loading…
Reference in New Issue