Make WordPress Core

Changeset 37532


Ignore:
Timestamp:
05/23/2016 02:57:19 PM (9 years ago)
Author:
ocean90
Message:

Database: Reduce the number of strtolower() calls in dbDelta().

Fixes #36919.

File:
1 edited

Legend:

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

    r37525 r37532  
    21932193            preg_match("|^([^ ]*)|", trim($fld), $fvals);
    21942194            $fieldname = trim( $fvals[1], '`' );
     2195            $fieldname_lowercased = strtolower( $fieldname );
    21952196
    21962197            // Verify the found field name.
    21972198            $validfield = true;
    2198             switch (strtolower($fieldname)) {
    2199             case '':
    2200             case 'primary':
    2201             case 'index':
    2202             case 'fulltext':
    2203             case 'unique':
    2204             case 'key':
    2205                 $validfield = false;
    2206                 $indices[] = trim(trim($fld), ", \n");
    2207                 break;
     2199            switch ( $fieldname_lowercased ) {
     2200                case '':
     2201                case 'primary':
     2202                case 'index':
     2203                case 'fulltext':
     2204                case 'unique':
     2205                case 'key':
     2206                    $validfield = false;
     2207                    $indices[] = trim(trim($fld), ", \n");
     2208                    break;
    22082209            }
    2209             $fld = trim($fld);
     2210            $fld = trim( $fld );
    22102211
    22112212            // If it's a valid field, add it to the field array.
    2212             if ($validfield) {
    2213                 $cfields[strtolower($fieldname)] = trim($fld, ", \n");
     2213            if ( $validfield ) {
     2214                $cfields[ $fieldname_lowercased ] = trim( $fld, ", \n" );
    22142215            }
    22152216        }
    22162217
    22172218        // For every field in the table.
    2218         foreach ($tablefields as $tablefield) {
     2219        foreach ( $tablefields as $tablefield ) {
     2220            $tablefield_field_lowercased = strtolower( $tablefield->Field );
     2221            $tablefield_type_lowercased = strtolower( $tablefield->Type );
    22192222
    22202223            // If the table field exists in the field array ...
    2221             if (array_key_exists(strtolower($tablefield->Field), $cfields)) {
     2224            if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
    22222225
    22232226                // Get the field type from the query.
    2224                 preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
     2227                preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[ $tablefield_field_lowercased ], $matches);
    22252228                $fieldtype = $matches[1];
     2229                $fieldtype_lowercased = strtolower( $fieldtype );
    22262230
    22272231                // Is actual field type different from the field type in query?
    22282232                if ($tablefield->Type != $fieldtype) {
    22292233                    $do_change = true;
    2230                     if ( in_array( strtolower( $fieldtype ), $text_fields ) && in_array( strtolower( $tablefield->Type ), $text_fields ) ) {
    2231                         if ( array_search( strtolower( $fieldtype ), $text_fields ) < array_search( strtolower( $tablefield->Type ), $text_fields ) ) {
     2234                    if ( in_array( $fieldtype_lowercased, $text_fields ) && in_array( $tablefield_type_lowercased, $text_fields ) ) {
     2235                        if ( array_search( $fieldtype_lowercased, $text_fields ) < array_search( $tablefield_type_lowercased, $text_fields ) ) {
    22322236                            $do_change = false;
    22332237                        }
    22342238                    }
    22352239
    2236                     if ( in_array( strtolower( $fieldtype ), $blob_fields ) && in_array( strtolower( $tablefield->Type ), $blob_fields ) ) {
    2237                         if ( array_search( strtolower( $fieldtype ), $blob_fields ) < array_search( strtolower( $tablefield->Type ), $blob_fields ) ) {
     2240                    if ( in_array( $fieldtype_lowercased, $blob_fields ) && in_array( $tablefield_type_lowercased, $blob_fields ) ) {
     2241                        if ( array_search( $fieldtype_lowercased, $blob_fields ) < array_search( $tablefield_type_lowercased, $blob_fields ) ) {
    22382242                            $do_change = false;
    22392243                        }
     
    22412245
    22422246                    if ( $do_change ) {
    2243                     // Add a query to change the column type
    2244                         $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
     2247                        // Add a query to change the column type.
     2248                        $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[ $tablefield_field_lowercased ];
    22452249                        $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
    22462250                    }
    22472251                }
    22482252
    2249                 // Get the default value from the array
     2253                // Get the default value from the array.
    22502254                    // todo: Remove this?
    22512255                    //echo "{$cfields[strtolower($tablefield->Field)]}<br>";
    2252                 if (preg_match("| DEFAULT '(.*?)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
     2256                if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) {
    22532257                    $default_value = $matches[1];
    22542258                    if ($tablefield->Default != $default_value) {
     
    22602264
    22612265                // Remove the field from the array (so it's not added).
    2262                 unset($cfields[strtolower($tablefield->Field)]);
     2266                unset( $cfields[ $tablefield_field_lowercased ] );
    22632267            } else {
    22642268                // This field exists in the table, but not in the creation queries?
Note: See TracChangeset for help on using the changeset viewer.