WordPress.org

Make WordPress Core

Changeset 19040


Ignore:
Timestamp:
10/21/11 22:35:33 (2 years ago)
Author:
nacin
Message:

Have dbDelta() loop through tables it knows about, rather than loop through a potentially expensive and definitely unnecessary SHOW TABLES. fixes #17998.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/upgrade.php

    r18899 r19040  
    14601460    $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries ); 
    14611461 
    1462     // Check to see which tables and fields exist 
    1463     if ($tables = $wpdb->get_col('SHOW TABLES;')) { 
    1464         // For every table in the database 
    1465         $global_tables = $wpdb->tables( 'global' ); 
    1466         foreach ($tables as $table) { 
    1467             // Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined. 
    1468             if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) ) 
    1469                 continue; 
    1470  
    1471             // If a table query exists for the database table... 
    1472             if ( array_key_exists(strtolower($table), $cqueries) ) { 
     1462    $global_tables = $wpdb->tables( 'global' ); 
     1463    foreach ( $cqueries as $table => $qry ) { 
     1464        // Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined. 
     1465        if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) ) 
     1466            continue; 
     1467 
     1468        // Fetch the table column structure from the database 
     1469        $wpdb->suppress_errors(); 
     1470        $tablefields = $wpdb->get_results("DESCRIBE {$table};"); 
     1471        $wpdb->suppress_errors( false ); 
     1472 
     1473        if ( ! $tablefields ) 
     1474            continue; 
     1475 
    14731476                // Clear the field and index arrays 
    14741477                $cfields = $indices = array(); 
    14751478                // Get all of the field names in the query from between the parens 
    1476                 preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2); 
     1479                preg_match("|\((.*)\)|ms", $qry, $match2); 
    14771480                $qryline = trim($match2[1]); 
    14781481 
     
    15081511                    } 
    15091512                } 
    1510  
    1511                 // Fetch the table column structure from the database 
    1512                 $tablefields = $wpdb->get_results("DESCRIBE {$table};"); 
    15131513 
    15141514                // For every field in the table 
     
    16081608                } 
    16091609 
    1610                 // Remove the original table creation query from processing 
    1611                 unset($cqueries[strtolower($table)]); 
    1612                 unset($for_update[strtolower($table)]); 
    1613             } else { 
    1614                 // This table exists in the database, but not in the creation queries? 
    1615             } 
    1616         } 
     1610        // Remove the original table creation query from processing 
     1611        unset( $cqueries[ $table ], $for_update[ $table ] ); 
    16171612    } 
    16181613 
Note: See TracChangeset for help on using the changeset viewer.