WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/01/2016 11:50:08 AM (4 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 includes the setUp() and tearDown() parts of [32270], to allow the tests to run, and fixes a typo them.

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

See #36748.

File:
1 edited

Legend:

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

    r33063 r37939  
    19501950    $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
    19511951
     1952    $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' );
     1953    $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' );
     1954
    19521955    $global_tables = $wpdb->tables( 'global' );
    19531956    foreach ( $cqueries as $table => $qry ) {
     
    20192022                // Is actual field type different from the field type in query?
    20202023                if ($tablefield->Type != $fieldtype) {
     2024                    $do_change = true;
     2025                    if ( in_array( strtolower( $fieldtype ), $text_fields ) && in_array( strtolower( $tablefield->Type ), $text_fields ) ) {
     2026                        if ( array_search( strtolower( $fieldtype ), $text_fields ) < array_search( strtolower( $tablefield->Type ), $text_fields ) ) {
     2027                            $do_change = false;
     2028                        }
     2029                    }
     2030
     2031                    if ( in_array( strtolower( $fieldtype ), $blob_fields ) && in_array( strtolower( $tablefield->Type ), $blob_fields ) ) {
     2032                        if ( array_search( strtolower( $fieldtype ), $blob_fields ) < array_search( strtolower( $tablefield->Type ), $blob_fields ) ) {
     2033                            $do_change = false;
     2034                        }
     2035                    }
     2036
     2037                    if ( $do_change ) {
    20212038                    // Add a query to change the column type
    2022                     $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
    2023                     $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
     2039                        $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
     2040                        $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
     2041                    }
    20242042                }
    20252043
Note: See TracChangeset for help on using the changeset viewer.