WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/01/2016 11:41:57 AM (6 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.

The FULLTEXT indexes are removed from the tests, as dbDelta()'s FULLTEXT support was added in WordPress 4.4.

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

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

See #36748.

File:
1 edited

Legend:

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

    r33950 r37938  
    20632063    $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
    20642064
     2065    $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' );
     2066    $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' );
     2067
    20652068    $global_tables = $wpdb->tables( 'global' );
    20662069    foreach ( $cqueries as $table => $qry ) {
     
    21322135                // Is actual field type different from the field type in query?
    21332136                if ($tablefield->Type != $fieldtype) {
     2137                    $do_change = true;
     2138                    if ( in_array( strtolower( $fieldtype ), $text_fields ) && in_array( strtolower( $tablefield->Type ), $text_fields ) ) {
     2139                        if ( array_search( strtolower( $fieldtype ), $text_fields ) < array_search( strtolower( $tablefield->Type ), $text_fields ) ) {
     2140                            $do_change = false;
     2141                        }
     2142                    }
     2143
     2144                    if ( in_array( strtolower( $fieldtype ), $blob_fields ) && in_array( strtolower( $tablefield->Type ), $blob_fields ) ) {
     2145                        if ( array_search( strtolower( $fieldtype ), $blob_fields ) < array_search( strtolower( $tablefield->Type ), $blob_fields ) ) {
     2146                            $do_change = false;
     2147                        }
     2148                    }
     2149
     2150                    if ( $do_change ) {
    21342151                    // Add a query to change the column type
    2135                     $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
    2136                     $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
     2152                        $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
     2153                        $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
     2154                    }
    21372155                }
    21382156
Note: See TracChangeset for help on using the changeset viewer.