Ticket #34870: 34870.2.diff
File 34870.2.diff, 4.1 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/upgrade.php
2216 2216 continue; 2217 2217 2218 2218 // Clear the field and index arrays. 2219 $cfields = $indices = array();2219 $cfields = $indices = $indices_without_subparts = array(); 2220 2220 2221 2221 // Get all of the field names in the query from between the parentheses. 2222 2222 preg_match("|\((.*)\)|ms", $qry, $match2); … … 2289 2289 $index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . strtolower( $index_matches['index_name'] ) . '`'; 2290 2290 2291 2291 // Parse the columns. Multiple columns are separated by a comma. 2292 $index_columns = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) );2292 $index_columns = $index_columns_without_subparts = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) ); 2293 2293 2294 2294 // Normalize columns. 2295 foreach ( $index_columns as &$index_column ) {2295 foreach ( $index_columns as $id => &$index_column ) { 2296 2296 // Extract column name and number of indexed characters (sub_part). 2297 2297 preg_match( 2298 2298 '/' … … 2319 2319 // Escape the column name with backticks. 2320 2320 $index_column = '`' . $index_column_matches['column_name'] . '`'; 2321 2321 2322 // We don't need to add the subpart to $index_columns_without_subparts 2323 $index_columns_without_subparts[ $id ] = $index_column; 2324 2322 2325 // Append the optional sup part with the number of indexed characters. 2323 2326 if ( isset( $index_column_matches['sub_part'] ) ) { 2324 2327 $index_column .= '(' . $index_column_matches['sub_part'] . ')'; … … 2327 2330 2328 2331 // Build the normalized index definition and add it to the list of indices. 2329 2332 $indices[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns ) . ")"; 2333 $indices_without_subparts[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns_without_subparts ) . ")"; 2330 2334 2331 2335 // Destroy no longer needed variables. 2332 unset( $index_column, $index_column_matches, $index_matches, $index_type, $index_name, $index_columns );2336 unset( $index_column, $index_column_matches, $index_matches, $index_type, $index_name, $index_columns, $index_columns_without_subparts ); 2333 2337 2334 2338 break; 2335 2339 } … … 2446 2450 2447 2451 // Add the field to the column list string. 2448 2452 $index_columns .= '`' . $column_data['fieldname'] . '`'; 2449 if ($column_data['subpart'] != '') {2450 $index_columns .= '('.$column_data['subpart'].')';2451 }2452 2453 } 2453 2454 2454 // The alternative index string doesn't care about subparts2455 $alt_index_columns = preg_replace( '/\([^)]*\)/', '', $index_columns );2456 2457 2455 // Add the column list to the index create string. 2458 $index_strings = array( 2459 "$index_string ($index_columns)", 2460 "$index_string ($alt_index_columns)", 2461 ); 2462 2463 foreach ( $index_strings as $index_string ) { 2464 if ( ! ( ( $aindex = array_search( $index_string, $indices ) ) === false ) ) { 2465 unset( $indices[ $aindex ] ); 2466 break; 2467 } 2456 $index_string .= " ($index_columns)"; 2457 2458 if ( ! ( ( $aindex = array_search( $index_string, $indices_without_subparts ) ) === false ) ) { 2459 unset( $indices_without_subparts[ $aindex ] ); 2460 unset( $indices[ $aindex ] ); 2468 2461 } 2469 2462 } 2470 2463 } -
tests/phpunit/tests/dbdelta.php
826 826 } 827 827 828 828 /** 829 * @ticket 34870 830 */ 831 function test_unchanged_key_lengths_do_not_recreate_index() { 832 global $wpdb; 833 834 $updates = dbDelta( 835 " 836 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 837 id bigint(20) NOT NULL AUTO_INCREMENT, 838 column_1 varchar(255) NOT NULL, 839 column_2 text, 840 column_3 blob, 841 PRIMARY KEY (id), 842 KEY key_1 (column_1(255)), 843 KEY compound_key (id,column_1), 844 FULLTEXT KEY fulltext_key (column_1) 845 ) ENGINE=MyISAM 846 ", false ); 847 848 $this->assertEmpty( $updates ); 849 } 850 851 /** 829 852 * @ticket 31679 830 853 */ 831 854 function test_column_type_change_with_hyphens_in_name() {