diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index dfe38d29e3..5030483769 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -2713,6 +2713,8 @@ function deslash( $content ) { * Useful for creating new tables and updating existing tables to a new structure. * * @since 1.5.0 + * @since 6.1.0 Ignores display width for integer data types on MySQL 8.0.17 or later, + * to match MySQL behavior. Note: This does not affect MariaDB. * * @global wpdb $wpdb WordPress database abstraction object. * @@ -2789,8 +2791,12 @@ function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.N $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' ); $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' ); + $int_fields = array( 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint' ); + + $global_tables = $wpdb->tables( 'global' ); + $db_version = $wpdb->db_version(); + $db_server_info = $wpdb->db_server_info(); - $global_tables = $wpdb->tables( 'global' ); foreach ( $cqueries as $table => $qry ) { // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal. if ( in_array( $table, $global_tables, true ) && ! wp_should_upgrade_global_tables() ) { @@ -2948,6 +2954,19 @@ function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.N $tablefield_field_lowercased = strtolower( $tablefield->Field ); $tablefield_type_lowercased = strtolower( $tablefield->Type ); + $tablefield_type_without_parentheses = preg_replace( + '/' + . '(.+)' // Field type, e.g. `int`. + . '\(\d*\)' // Display width. + . '(.*)' // Optional attributes, e.g. `unsigned`. + . '/', + '$1$2', + $tablefield_type_lowercased + ); + + // Get the type without attributes, e.g. `int`. + $tablefield_type_base = strtok( $tablefield_type_without_parentheses, ' ' ); + // If the table field exists in the field array... if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) { @@ -2956,6 +2975,19 @@ function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.N $fieldtype = $matches[1]; $fieldtype_lowercased = strtolower( $fieldtype ); + $fieldtype_without_parentheses = preg_replace( + '/' + . '(.+)' // Field type, e.g. `int`. + . '\(\d*\)' // Display width. + . '(.*)' // Optional attributes, e.g. `unsigned`. + . '/', + '$1$2', + $fieldtype_lowercased + ); + + // Get the type without attributes, e.g. `int`. + $fieldtype_base = strtok( $fieldtype_without_parentheses, ' ' ); + // Is actual field type different from the field type in query? if ( $tablefield->Type != $fieldtype ) { $do_change = true; @@ -2971,6 +3003,21 @@ function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.N } } + if ( in_array( $fieldtype_base, $int_fields, true ) && in_array( $tablefield_type_base, $int_fields, true ) + && $fieldtype_without_parentheses === $tablefield_type_without_parentheses + ) { + /* + * MySQL 8.0.17 or later does not support display width for integer data types, + * so if display width is the only difference, it can be safely ignored. + * Note: This is specific to MySQL and does not affect MariaDB. + */ + if ( version_compare( $db_version, '8.0.17', '>=' ) + && ! str_contains( $db_server_info, 'MariaDB' ) + ) { + $do_change = false; + } + } + if ( $do_change ) { // Add a query to change the column type. $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ]; diff --git a/wp-includes/version.php b/wp-includes/version.php index c40100342c..533ebf6e50 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53896'; +$wp_version = '6.1-alpha-53897'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.