Changeset 37532
- Timestamp:
- 05/23/2016 02:57:19 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r37525 r37532 2193 2193 preg_match("|^([^ ]*)|", trim($fld), $fvals); 2194 2194 $fieldname = trim( $fvals[1], '`' ); 2195 $fieldname_lowercased = strtolower( $fieldname ); 2195 2196 2196 2197 // Verify the found field name. 2197 2198 $validfield = true; 2198 switch ( strtolower($fieldname)) {2199 case '':2200 case 'primary':2201 case 'index':2202 case 'fulltext':2203 case 'unique':2204 case 'key':2205 $validfield = false;2206 $indices[] = trim(trim($fld), ", \n");2207 break;2199 switch ( $fieldname_lowercased ) { 2200 case '': 2201 case 'primary': 2202 case 'index': 2203 case 'fulltext': 2204 case 'unique': 2205 case 'key': 2206 $validfield = false; 2207 $indices[] = trim(trim($fld), ", \n"); 2208 break; 2208 2209 } 2209 $fld = trim( $fld);2210 $fld = trim( $fld ); 2210 2211 2211 2212 // If it's a valid field, add it to the field array. 2212 if ( $validfield) {2213 $cfields[ strtolower($fieldname)] = trim($fld, ", \n");2213 if ( $validfield ) { 2214 $cfields[ $fieldname_lowercased ] = trim( $fld, ", \n" ); 2214 2215 } 2215 2216 } 2216 2217 2217 2218 // For every field in the table. 2218 foreach ($tablefields as $tablefield) { 2219 foreach ( $tablefields as $tablefield ) { 2220 $tablefield_field_lowercased = strtolower( $tablefield->Field ); 2221 $tablefield_type_lowercased = strtolower( $tablefield->Type ); 2219 2222 2220 2223 // If the table field exists in the field array ... 2221 if ( array_key_exists(strtolower($tablefield->Field), $cfields)) {2224 if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) { 2222 2225 2223 2226 // Get the field type from the query. 2224 preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[ strtolower($tablefield->Field)], $matches);2227 preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[ $tablefield_field_lowercased ], $matches); 2225 2228 $fieldtype = $matches[1]; 2229 $fieldtype_lowercased = strtolower( $fieldtype ); 2226 2230 2227 2231 // Is actual field type different from the field type in query? 2228 2232 if ($tablefield->Type != $fieldtype) { 2229 2233 $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 ) ) {2234 if ( in_array( $fieldtype_lowercased, $text_fields ) && in_array( $tablefield_type_lowercased, $text_fields ) ) { 2235 if ( array_search( $fieldtype_lowercased, $text_fields ) < array_search( $tablefield_type_lowercased, $text_fields ) ) { 2232 2236 $do_change = false; 2233 2237 } 2234 2238 } 2235 2239 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 ) ) {2240 if ( in_array( $fieldtype_lowercased, $blob_fields ) && in_array( $tablefield_type_lowercased, $blob_fields ) ) { 2241 if ( array_search( $fieldtype_lowercased, $blob_fields ) < array_search( $tablefield_type_lowercased, $blob_fields ) ) { 2238 2242 $do_change = false; 2239 2243 } … … 2241 2245 2242 2246 if ( $do_change ) { 2243 // Add a query to change the column type2244 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[ strtolower($tablefield->Field)];2247 // Add a query to change the column type. 2248 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[ $tablefield_field_lowercased ]; 2245 2249 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2246 2250 } 2247 2251 } 2248 2252 2249 // Get the default value from the array 2253 // Get the default value from the array. 2250 2254 // todo: Remove this? 2251 2255 //echo "{$cfields[strtolower($tablefield->Field)]}<br>"; 2252 if ( preg_match("| DEFAULT '(.*?)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {2256 if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) { 2253 2257 $default_value = $matches[1]; 2254 2258 if ($tablefield->Default != $default_value) { … … 2260 2264 2261 2265 // Remove the field from the array (so it's not added). 2262 unset( $cfields[strtolower($tablefield->Field)]);2266 unset( $cfields[ $tablefield_field_lowercased ] ); 2263 2267 } else { 2264 2268 // This field exists in the table, but not in the creation queries?
Note: See TracChangeset
for help on using the changeset viewer.