WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/01/2016 12:58:36 PM (4 years ago)
Author:
ocean90
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.

Merge of [37525] to the 4.5 branch.

Props pento.
See #36748.

Location:
branches/4.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.5

  • branches/4.5/src/wp-admin/includes/upgrade.php

    r36985 r37606  
    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.