Make WordPress Core


Ignore:
Timestamp:
05/23/2016 08:35:59 AM (8 years ago)
Author:
pento
Message:

Database: dbDelta() will no longer try to downgrade the size of TEXT and BLOB columns.

When upgrading to utf8mb4, TEXT fields will be upgraded to MEDIUMTEXT (and likewise for all other *TEXT and *BLOB fields). This is to allow for the additional space requirements of utf8mb4.

On the subsequent upgrade, after the utf8mb4 upgrade, dbDelta() would try and downgrade the fields to their original size again. At best, this it a waste of time, at worst, this could truncate any data larger than the original size. There's no harm in leaving them at their original size, so let's do that.

Fixes #36748.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/upgrade.php

    r37488 r37525  
    21552155    $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
    21562156
     2157    $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' );
     2158    $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' );
     2159
    21572160    $global_tables = $wpdb->tables( 'global' );
    21582161    foreach ( $cqueries as $table => $qry ) {
     
    22242227                // Is actual field type different from the field type in query?
    22252228                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 ) {
    22262243                    // 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                    }
    22292247                }
    22302248
Note: See TracChangeset for help on using the changeset viewer.