WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/01/2016 06:58:40 AM (5 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, 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 new size, so let's do that.

This also fixes a typo in the dbDelta() tests.

Merge of [37525] to the 4.4 branch.
Partial merge of [36552] to the 4.4 branch.

See #36748.

File:
1 edited

Legend:

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

    r35701 r37936  
    20972097    $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
    20982098
     2099    $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' );
     2100    $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' );
     2101
    20992102    $global_tables = $wpdb->tables( 'global' );
    21002103    foreach ( $cqueries as $table => $qry ) {
     
    21662169                // Is actual field type different from the field type in query?
    21672170                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 ) {
    21682185                    // 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                    }
    21712189                }
    21722190
Note: See TracChangeset for help on using the changeset viewer.