- Timestamp:
- 05/23/2016 08:35:59 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r37488 r37525 2155 2155 $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries ); 2156 2156 2157 $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' ); 2158 $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' ); 2159 2157 2160 $global_tables = $wpdb->tables( 'global' ); 2158 2161 foreach ( $cqueries as $table => $qry ) { … … 2224 2227 // Is actual field type different from the field type in query? 2225 2228 if ($tablefield->Type != $fieldtype) { 2229 $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 ) ) { 2232 $do_change = false; 2233 } 2234 } 2235 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 ) ) { 2238 $do_change = false; 2239 } 2240 } 2241 2242 if ( $do_change ) { 2226 2243 // Add a query to change the column type 2227 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; 2228 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2244 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; 2245 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2246 } 2229 2247 } 2230 2248 -
trunk/tests/phpunit/tests/dbdelta.php
r36552 r37525 32 32 id bigint(20) NOT NULL AUTO_INCREMENT, 33 33 column_1 varchar(255) NOT NULL, 34 column_2 text, 35 column_3 blob, 34 36 PRIMARY KEY (id), 35 37 KEY key_1 (column_1), … … 363 365 $this->assertSame( array(), $actual ); 364 366 } 367 368 /** 369 * @ticket 36748 370 */ 371 function test_dont_downsize_text_fields() { 372 global $wpdb; 373 374 $result = dbDelta( 375 " 376 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 377 id bigint(20) NOT NULL AUTO_INCREMENT, 378 column_1 varchar(255) NOT NULL, 379 column_2 tinytext, 380 column_3 blob, 381 PRIMARY KEY (id), 382 KEY key_1 (column_1), 383 KEY compound_key (id,column_1), 384 FULLTEXT KEY fulltext_key (column_1) 385 ) ENGINE=MyISAM 386 ", false ); 387 388 $this->assertSame( array(), $result ); 389 } 390 391 /** 392 * @ticket 36748 393 */ 394 function test_dont_downsize_blob_fields() { 395 global $wpdb; 396 397 $result = dbDelta( 398 " 399 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 400 id bigint(20) NOT NULL AUTO_INCREMENT, 401 column_1 varchar(255) NOT NULL, 402 column_2 text, 403 column_3 tinyblob, 404 PRIMARY KEY (id), 405 KEY key_1 (column_1), 406 KEY compound_key (id,column_1), 407 FULLTEXT KEY fulltext_key (column_1) 408 ) ENGINE=MyISAM 409 ", false ); 410 411 $this->assertSame( array(), $result ); 412 } 413 414 /** 415 * @ticket 36748 416 */ 417 function test_upsize_text_fields() { 418 global $wpdb; 419 420 $result = dbDelta( 421 " 422 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 423 id bigint(20) NOT NULL AUTO_INCREMENT, 424 column_1 varchar(255) NOT NULL, 425 column_2 bigtext, 426 column_3 blob, 427 PRIMARY KEY (id), 428 KEY key_1 (column_1), 429 KEY compound_key (id,column_1), 430 FULLTEXT KEY fulltext_key (column_1) 431 ) ENGINE=MyISAM 432 ", false ); 433 434 $this->assertSame( 435 array( 436 "{$wpdb->prefix}dbdelta_test.column_2" 437 => "Changed type of {$wpdb->prefix}dbdelta_test.column_2 from text to bigtext" 438 ), $result ); 439 } 440 441 /** 442 * @ticket 36748 443 */ 444 function test_upsize_blob_fields() { 445 global $wpdb; 446 447 $result = dbDelta( 448 " 449 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 450 id bigint(20) NOT NULL AUTO_INCREMENT, 451 column_1 varchar(255) NOT NULL, 452 column_2 text, 453 column_3 mediumblob, 454 PRIMARY KEY (id), 455 KEY key_1 (column_1), 456 KEY compound_key (id,column_1), 457 FULLTEXT KEY fulltext_key (column_1) 458 ) ENGINE=MyISAM 459 ", false ); 460 461 $this->assertSame( 462 array( 463 "{$wpdb->prefix}dbdelta_test.column_3" 464 => "Changed type of {$wpdb->prefix}dbdelta_test.column_3 from blob to mediumblob" 465 ), $result ); 466 } 365 467 }
Note: See TracChangeset
for help on using the changeset viewer.