Make WordPress Core

Ticket #10404: dbDelta_match_extra_spacing.diff

File dbDelta_match_extra_spacing.diff, 2.1 KB (added by jbutkus, 12 years ago)

Ignore whitespace issues within dbDelta duplicates recognition

  • wp-admin/includes/upgrade.php

     
    14501450}
    14511451
    14521452/**
     1453 * Unify index line, to perform unique cross-matches
     1454 *
     1455 * Remove extra whitespaces, replace 'INDEX' for 'KEY'.
     1456 *
     1457 * @param string $input Index options line
     1458 *
     1459 * @return string Unified index options line
     1460 */
     1461function dbDelta_unifyIndexLine( $input ) {
     1462        $input = trim( $input );
     1463        $input = trim( $input, ", \n" );
     1464        $input = preg_replace( '#\s+#',                   ' ',     $input );
     1465        $input = preg_replace( '#\s+\(\s*(\d+)\s*\)#',    '(\1)',  $input );
     1466        $input = preg_replace( '#([^\s])\s*,\s*([^\s])#', '\1,\2', $input );
     1467        $input = preg_replace( '#^INDEX\s+#',             'KEY ',  $input );
     1468        return $input;
     1469}
     1470
     1471/**
    14531472 * {@internal Missing Short Description}}
    14541473 *
    14551474 * {@internal Missing Long Description}}
     
    15361555                        case 'unique':
    15371556                        case 'key':
    15381557                                $validfield = false;
    1539                                 $indices[] = trim(trim($fld), ", \n");
     1558                                $indices[] = dbDelta_unifyIndexLine( $fld );
    15401559                                break;
    15411560                        }
    15421561                        $fld = trim($fld);
     
    15521571                        // If the table field exists in the field array...
    15531572                        if (array_key_exists(strtolower($tablefield->Field), $cfields)) {
    15541573                                // Get the field type from the query
    1555                                 preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
     1574                                preg_match("|".$tablefield->Field."\s+([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
    15561575                                $fieldtype = $matches[1];
    15571576
    15581577                                // Is actual field type different from the field type in query?
     
    16281647                                }
    16291648                                // Add the column list to the index create string
    16301649                                $index_string .= ' ('.$index_columns.')';
     1650                                $index_string = dbDelta_unifyIndexLine( $index_string );
    16311651                                if (!(($aindex = array_search($index_string, $indices)) === false)) {
    16321652                                        unset($indices[$aindex]);
    16331653                                        //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";