Changeset 39921
- Timestamp:
- 01/17/2017 04:00:09 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r39754 r39921 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. … … 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( … … 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'] ) ) { … … 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; … … 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 // Check if the index definition exists, ignoring subparts. 2459 if ( ! ( ( $aindex = array_search( $index_string, $indices_without_subparts ) ) === false ) ) { 2460 // If the index already exists (even with different subparts), we don't need to create it. 2461 unset( $indices_without_subparts[ $aindex ] ); 2462 unset( $indices[ $aindex ] ); 2468 2463 } 2469 2464 } -
trunk/tests/phpunit/tests/dbdelta.php
r38591 r39921 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 /** 852 * @ticket 34870 853 */ 854 function test_changed_key_lengths_do_not_recreate_index() { 855 global $wpdb; 856 857 $updates = dbDelta( 858 " 859 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 860 id bigint(20) NOT NULL AUTO_INCREMENT, 861 column_1 varchar(255) NOT NULL, 862 column_2 text, 863 column_3 blob, 864 PRIMARY KEY (id), 865 KEY key_1 (column_1), 866 KEY compound_key (id,column_1), 867 KEY changing_key_length (column_1(20)), 868 FULLTEXT KEY fulltext_key (column_1) 869 ) ENGINE=MyISAM 870 " ); 871 872 $this->assertSame( array( 873 "Added index {$wpdb->prefix}dbdelta_test KEY `changing_key_length` (`column_1`(20))" 874 ), $updates ); 875 876 $updates = dbDelta( 877 " 878 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 879 id bigint(20) NOT NULL AUTO_INCREMENT, 880 column_1 varchar(255) NOT NULL, 881 column_2 text, 882 column_3 blob, 883 PRIMARY KEY (id), 884 KEY key_1 (column_1), 885 KEY compound_key (id,column_1), 886 KEY changing_key_length (column_1(50)), 887 FULLTEXT KEY fulltext_key (column_1) 888 ) ENGINE=MyISAM 889 " ); 890 891 $this->assertEmpty( $updates ); 892 893 $updates = dbDelta( 894 " 895 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 896 id bigint(20) NOT NULL AUTO_INCREMENT, 897 column_1 varchar(255) NOT NULL, 898 column_2 text, 899 column_3 blob, 900 PRIMARY KEY (id), 901 KEY key_1 (column_1), 902 KEY compound_key (id,column_1), 903 KEY changing_key_length (column_1(1)), 904 FULLTEXT KEY fulltext_key (column_1) 905 ) ENGINE=MyISAM 906 " ); 907 908 $this->assertEmpty( $updates ); 909 910 $updates = dbDelta( 911 " 912 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 913 id bigint(20) NOT NULL AUTO_INCREMENT, 914 column_1 varchar(255) NOT NULL, 915 column_2 text, 916 column_3 blob, 917 PRIMARY KEY (id), 918 KEY key_1 (column_1), 919 KEY compound_key (id,column_1), 920 KEY changing_key_length (column_1), 921 FULLTEXT KEY fulltext_key (column_1) 922 ) ENGINE=MyISAM 923 " ); 924 925 $this->assertEmpty( $updates ); 926 } 927 928 /** 829 929 * @ticket 31679 830 930 */
Note: See TracChangeset
for help on using the changeset viewer.