Changeset 37938
- Timestamp:
- 07/01/2016 11:41:57 AM (8 years ago)
- Location:
- branches/4.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.3/src/wp-admin/includes/upgrade.php
r33950 r37938 2063 2063 $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries ); 2064 2064 2065 $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' ); 2066 $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' ); 2067 2065 2068 $global_tables = $wpdb->tables( 'global' ); 2066 2069 foreach ( $cqueries as $table => $qry ) { … … 2132 2135 // Is actual field type different from the field type in query? 2133 2136 if ($tablefield->Type != $fieldtype) { 2137 $do_change = true; 2138 if ( in_array( strtolower( $fieldtype ), $text_fields ) && in_array( strtolower( $tablefield->Type ), $text_fields ) ) { 2139 if ( array_search( strtolower( $fieldtype ), $text_fields ) < array_search( strtolower( $tablefield->Type ), $text_fields ) ) { 2140 $do_change = false; 2141 } 2142 } 2143 2144 if ( in_array( strtolower( $fieldtype ), $blob_fields ) && in_array( strtolower( $tablefield->Type ), $blob_fields ) ) { 2145 if ( array_search( strtolower( $fieldtype ), $blob_fields ) < array_search( strtolower( $tablefield->Type ), $blob_fields ) ) { 2146 $do_change = false; 2147 } 2148 } 2149 2150 if ( $do_change ) { 2134 2151 // Add a query to change the column type 2135 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; 2136 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2152 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; 2153 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2154 } 2137 2155 } 2138 2156 -
branches/4.3/tests/phpunit/tests/dbdelta.php
r33425 r37938 31 31 id bigint(20) NOT NULL AUTO_INCREMENT, 32 32 column_1 varchar(255) NOT NULL, 33 PRIMARY KEY (id), 34 KEY key_1 (column_1), 35 KEY compoud_key (id,column_1) 33 column_2 text, 34 column_3 blob, 35 PRIMARY KEY (id), 36 KEY key_1 (column_1), 37 KEY compound_key (id,column_1) 36 38 ) 37 39 " … … 104 106 PRIMARY KEY (id), 105 107 KEY key_1 (column_1), 106 KEY compou d_key (id,column_1)108 KEY compound_key (id,column_1) 107 109 ) 108 110 " … … 127 129 PRIMARY KEY (id), 128 130 KEY key_1 (column_1), 129 KEY compou d_key (id,column_1)131 KEY compound_key (id,column_1) 130 132 ) 131 133 " … … 156 158 PRIMARY KEY (id), 157 159 KEY key_1 (column_1), 158 KEY compou d_key (id,column_1)160 KEY compound_key (id,column_1) 159 161 ) 160 162 " … … 188 190 PRIMARY KEY (id), 189 191 KEY key_1 (column_1), 190 KEY compou d_key (id,column_1)192 KEY compound_key (id,column_1) 191 193 ) 192 194 " … … 214 216 PRIMARY KEY (id), 215 217 KEY key_1 (column_1), 216 KEY compou d_key (id,column_1)218 KEY compound_key (id,column_1) 217 219 ) 218 220 " … … 323 325 $this->assertSame( array(), $actual ); 324 326 } 327 328 /** 329 * @ticket 36748 330 */ 331 function test_dont_downsize_text_fields() { 332 global $wpdb; 333 334 $result = dbDelta( 335 " 336 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 337 id bigint(20) NOT NULL AUTO_INCREMENT, 338 column_1 varchar(255) NOT NULL, 339 column_2 tinytext, 340 column_3 blob, 341 PRIMARY KEY (id), 342 KEY key_1 (column_1), 343 KEY compound_key (id,column_1) 344 ) ENGINE=MyISAM 345 ", false ); 346 347 $this->assertSame( array(), $result ); 348 } 349 350 /** 351 * @ticket 36748 352 */ 353 function test_dont_downsize_blob_fields() { 354 global $wpdb; 355 356 $result = dbDelta( 357 " 358 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 359 id bigint(20) NOT NULL AUTO_INCREMENT, 360 column_1 varchar(255) NOT NULL, 361 column_2 text, 362 column_3 tinyblob, 363 PRIMARY KEY (id), 364 KEY key_1 (column_1), 365 KEY compound_key (id,column_1) 366 ) ENGINE=MyISAM 367 ", false ); 368 369 $this->assertSame( array(), $result ); 370 } 371 372 /** 373 * @ticket 36748 374 */ 375 function test_upsize_text_fields() { 376 global $wpdb; 377 378 $result = dbDelta( 379 " 380 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 381 id bigint(20) NOT NULL AUTO_INCREMENT, 382 column_1 varchar(255) NOT NULL, 383 column_2 bigtext, 384 column_3 blob, 385 PRIMARY KEY (id), 386 KEY key_1 (column_1), 387 KEY compound_key (id,column_1) 388 ) ENGINE=MyISAM 389 ", false ); 390 391 $this->assertSame( 392 array( 393 "{$wpdb->prefix}dbdelta_test.column_2" 394 => "Changed type of {$wpdb->prefix}dbdelta_test.column_2 from text to bigtext" 395 ), $result ); 396 } 397 398 /** 399 * @ticket 36748 400 */ 401 function test_upsize_blob_fields() { 402 global $wpdb; 403 404 $result = dbDelta( 405 " 406 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 407 id bigint(20) NOT NULL AUTO_INCREMENT, 408 column_1 varchar(255) NOT NULL, 409 column_2 text, 410 column_3 mediumblob, 411 PRIMARY KEY (id), 412 KEY key_1 (column_1), 413 KEY compound_key (id,column_1) 414 ) ENGINE=MyISAM 415 ", false ); 416 417 $this->assertSame( 418 array( 419 "{$wpdb->prefix}dbdelta_test.column_3" 420 => "Changed type of {$wpdb->prefix}dbdelta_test.column_3 from blob to mediumblob" 421 ), $result ); 422 } 325 423 }
Note: See TracChangeset
for help on using the changeset viewer.