Changeset 37936
- Timestamp:
- 07/01/2016 06:58:40 AM (8 years ago)
- Location:
- branches/4.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.4/src/wp-admin/includes/upgrade.php
r35701 r37936 2097 2097 $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries ); 2098 2098 2099 $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' ); 2100 $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' ); 2101 2099 2102 $global_tables = $wpdb->tables( 'global' ); 2100 2103 foreach ( $cqueries as $table => $qry ) { … … 2166 2169 // Is actual field type different from the field type in query? 2167 2170 if ($tablefield->Type != $fieldtype) { 2171 $do_change = true; 2172 if ( in_array( strtolower( $fieldtype ), $text_fields ) && in_array( strtolower( $tablefield->Type ), $text_fields ) ) { 2173 if ( array_search( strtolower( $fieldtype ), $text_fields ) < array_search( strtolower( $tablefield->Type ), $text_fields ) ) { 2174 $do_change = false; 2175 } 2176 } 2177 2178 if ( in_array( strtolower( $fieldtype ), $blob_fields ) && in_array( strtolower( $tablefield->Type ), $blob_fields ) ) { 2179 if ( array_search( strtolower( $fieldtype ), $blob_fields ) < array_search( strtolower( $tablefield->Type ), $blob_fields ) ) { 2180 $do_change = false; 2181 } 2182 } 2183 2184 if ( $do_change ) { 2168 2185 // Add a query to change the column type 2169 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; 2170 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2186 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; 2187 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2188 } 2171 2189 } 2172 2190 -
branches/4.4/tests/phpunit/tests/dbdelta.php
r35487 r37936 32 32 id bigint(20) NOT NULL AUTO_INCREMENT, 33 33 column_1 varchar(255) NOT NULL, 34 PRIMARY KEY (id), 35 KEY key_1 (column_1), 36 KEY compoud_key (id,column_1), 34 column_2 text, 35 column_3 blob, 36 PRIMARY KEY (id), 37 KEY key_1 (column_1), 38 KEY compound_key (id,column_1), 37 39 FULLTEXT KEY fulltext_key (column_1) 38 40 ) ENGINE=MyISAM … … 106 108 PRIMARY KEY (id), 107 109 KEY key_1 (column_1), 108 KEY compou d_key (id,column_1)110 KEY compound_key (id,column_1) 109 111 ) 110 112 " … … 129 131 PRIMARY KEY (id), 130 132 KEY key_1 (column_1), 131 KEY compou d_key (id,column_1)133 KEY compound_key (id,column_1) 132 134 ) 133 135 " … … 158 160 PRIMARY KEY (id), 159 161 KEY key_1 (column_1), 160 KEY compou d_key (id,column_1)162 KEY compound_key (id,column_1) 161 163 ) 162 164 " … … 190 192 PRIMARY KEY (id), 191 193 KEY key_1 (column_1), 192 KEY compou d_key (id,column_1)194 KEY compound_key (id,column_1) 193 195 ) 194 196 " … … 216 218 PRIMARY KEY (id), 217 219 KEY key_1 (column_1), 218 KEY compou d_key (id,column_1)220 KEY compound_key (id,column_1) 219 221 ) 220 222 " … … 266 268 PRIMARY KEY (id), 267 269 KEY key_1 (column_1), 268 KEY compou d_key (id,column_1),270 KEY compound_key (id,column_1), 269 271 FULLTEXT KEY fulltext_key (column_1) 270 272 ) … … 348 350 $this->assertSame( array(), $actual ); 349 351 } 352 353 /** 354 * @ticket 36748 355 */ 356 function test_dont_downsize_text_fields() { 357 global $wpdb; 358 359 $result = dbDelta( 360 " 361 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 362 id bigint(20) NOT NULL AUTO_INCREMENT, 363 column_1 varchar(255) NOT NULL, 364 column_2 tinytext, 365 column_3 blob, 366 PRIMARY KEY (id), 367 KEY key_1 (column_1), 368 KEY compound_key (id,column_1), 369 FULLTEXT KEY fulltext_key (column_1) 370 ) ENGINE=MyISAM 371 ", false ); 372 373 $this->assertSame( array(), $result ); 374 } 375 376 /** 377 * @ticket 36748 378 */ 379 function test_dont_downsize_blob_fields() { 380 global $wpdb; 381 382 $result = dbDelta( 383 " 384 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 385 id bigint(20) NOT NULL AUTO_INCREMENT, 386 column_1 varchar(255) NOT NULL, 387 column_2 text, 388 column_3 tinyblob, 389 PRIMARY KEY (id), 390 KEY key_1 (column_1), 391 KEY compound_key (id,column_1), 392 FULLTEXT KEY fulltext_key (column_1) 393 ) ENGINE=MyISAM 394 ", false ); 395 396 $this->assertSame( array(), $result ); 397 } 398 399 /** 400 * @ticket 36748 401 */ 402 function test_upsize_text_fields() { 403 global $wpdb; 404 405 $result = dbDelta( 406 " 407 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 408 id bigint(20) NOT NULL AUTO_INCREMENT, 409 column_1 varchar(255) NOT NULL, 410 column_2 bigtext, 411 column_3 blob, 412 PRIMARY KEY (id), 413 KEY key_1 (column_1), 414 KEY compound_key (id,column_1), 415 FULLTEXT KEY fulltext_key (column_1) 416 ) ENGINE=MyISAM 417 ", false ); 418 419 $this->assertSame( 420 array( 421 "{$wpdb->prefix}dbdelta_test.column_2" 422 => "Changed type of {$wpdb->prefix}dbdelta_test.column_2 from text to bigtext" 423 ), $result ); 424 } 425 426 /** 427 * @ticket 36748 428 */ 429 function test_upsize_blob_fields() { 430 global $wpdb; 431 432 $result = dbDelta( 433 " 434 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 435 id bigint(20) NOT NULL AUTO_INCREMENT, 436 column_1 varchar(255) NOT NULL, 437 column_2 text, 438 column_3 mediumblob, 439 PRIMARY KEY (id), 440 KEY key_1 (column_1), 441 KEY compound_key (id,column_1), 442 FULLTEXT KEY fulltext_key (column_1) 443 ) ENGINE=MyISAM 444 ", false ); 445 446 $this->assertSame( 447 array( 448 "{$wpdb->prefix}dbdelta_test.column_3" 449 => "Changed type of {$wpdb->prefix}dbdelta_test.column_3 from blob to mediumblob" 450 ), $result ); 451 } 350 452 }
Note: See TracChangeset
for help on using the changeset viewer.