Changeset 37939
- Timestamp:
- 07/01/2016 11:50:08 AM (8 years ago)
- Location:
- branches/4.2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.2/src/wp-admin/includes/upgrade.php
r33063 r37939 1950 1950 $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries ); 1951 1951 1952 $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' ); 1953 $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' ); 1954 1952 1955 $global_tables = $wpdb->tables( 'global' ); 1953 1956 foreach ( $cqueries as $table => $qry ) { … … 2019 2022 // Is actual field type different from the field type in query? 2020 2023 if ($tablefield->Type != $fieldtype) { 2024 $do_change = true; 2025 if ( in_array( strtolower( $fieldtype ), $text_fields ) && in_array( strtolower( $tablefield->Type ), $text_fields ) ) { 2026 if ( array_search( strtolower( $fieldtype ), $text_fields ) < array_search( strtolower( $tablefield->Type ), $text_fields ) ) { 2027 $do_change = false; 2028 } 2029 } 2030 2031 if ( in_array( strtolower( $fieldtype ), $blob_fields ) && in_array( strtolower( $tablefield->Type ), $blob_fields ) ) { 2032 if ( array_search( strtolower( $fieldtype ), $blob_fields ) < array_search( strtolower( $tablefield->Type ), $blob_fields ) ) { 2033 $do_change = false; 2034 } 2035 } 2036 2037 if ( $do_change ) { 2021 2038 // Add a query to change the column type 2022 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; 2023 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2039 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; 2040 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2041 } 2024 2042 } 2025 2043 -
branches/4.2/tests/phpunit/tests/dbdelta.php
r32108 r37939 9 9 class Tests_dbDelta extends WP_UnitTestCase { 10 10 11 /** 12 * Make sure the upgrade code is loaded before the tests are run. 13 */ 14 public static function setUpBeforeClass() { 15 16 parent::setUpBeforeClass(); 17 18 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 19 } 20 21 /** 22 * Create a custom table to be used in each test. 23 */ 24 public function setUp() { 25 26 global $wpdb; 27 28 $wpdb->query( 29 " 30 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 31 id bigint(20) NOT NULL AUTO_INCREMENT, 32 column_1 varchar(255) NOT NULL, 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) 38 ) 39 " 40 ); 41 42 parent::setUp(); 43 } 44 45 /** 46 * Delete the custom table on teardown. 47 */ 48 public function tearDown() { 49 50 global $wpdb; 51 52 parent::tearDown(); 53 54 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test" ); 55 } 56 11 57 function test_create_new_table() { 12 include_once( ABSPATH . 'wp-admin/includes/upgrade.php');13 58 $table_name = 'test_new_table'; 14 59 … … 41 86 $this->assertSame( array(), $actual ); 42 87 } 88 89 /** 90 * @ticket 36748 91 */ 92 function test_dont_downsize_text_fields() { 93 global $wpdb; 94 95 $result = dbDelta( 96 " 97 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 98 id bigint(20) NOT NULL AUTO_INCREMENT, 99 column_1 varchar(255) NOT NULL, 100 column_2 tinytext, 101 column_3 blob, 102 PRIMARY KEY (id), 103 KEY key_1 (column_1), 104 KEY compound_key (id,column_1) 105 ) ENGINE=MyISAM 106 ", false ); 107 108 $this->assertSame( array(), $result ); 109 } 110 111 /** 112 * @ticket 36748 113 */ 114 function test_dont_downsize_blob_fields() { 115 global $wpdb; 116 117 $result = dbDelta( 118 " 119 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 120 id bigint(20) NOT NULL AUTO_INCREMENT, 121 column_1 varchar(255) NOT NULL, 122 column_2 text, 123 column_3 tinyblob, 124 PRIMARY KEY (id), 125 KEY key_1 (column_1), 126 KEY compound_key (id,column_1) 127 ) ENGINE=MyISAM 128 ", false ); 129 130 $this->assertSame( array(), $result ); 131 } 132 133 /** 134 * @ticket 36748 135 */ 136 function test_upsize_text_fields() { 137 global $wpdb; 138 139 $result = dbDelta( 140 " 141 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 142 id bigint(20) NOT NULL AUTO_INCREMENT, 143 column_1 varchar(255) NOT NULL, 144 column_2 bigtext, 145 column_3 blob, 146 PRIMARY KEY (id), 147 KEY key_1 (column_1), 148 KEY compound_key (id,column_1) 149 ) ENGINE=MyISAM 150 ", false ); 151 152 $this->assertSame( 153 array( 154 "{$wpdb->prefix}dbdelta_test.column_2" 155 => "Changed type of {$wpdb->prefix}dbdelta_test.column_2 from text to bigtext" 156 ), $result ); 157 } 158 159 /** 160 * @ticket 36748 161 */ 162 function test_upsize_blob_fields() { 163 global $wpdb; 164 165 $result = dbDelta( 166 " 167 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 168 id bigint(20) NOT NULL AUTO_INCREMENT, 169 column_1 varchar(255) NOT NULL, 170 column_2 text, 171 column_3 mediumblob, 172 PRIMARY KEY (id), 173 KEY key_1 (column_1), 174 KEY compound_key (id,column_1) 175 ) ENGINE=MyISAM 176 ", false ); 177 178 $this->assertSame( 179 array( 180 "{$wpdb->prefix}dbdelta_test.column_3" 181 => "Changed type of {$wpdb->prefix}dbdelta_test.column_3 from blob to mediumblob" 182 ), $result ); 183 } 43 184 }
Note: See TracChangeset
for help on using the changeset viewer.