Make WordPress Core


Ignore:
Timestamp:
10/04/2022 03:39:28 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Database: Correct MariaDB version check in wpdb::has_cap().

MariaDB version is reported differently between PHP versions:

  • PHP 8.0.16 or later: 10.6.8-MariaDB
  • PHP 8.0.15 or earlier: 5.5.5-10.6.8-MariaDB

The latter includes PHP 7.4.x and PHP 5.6.x as well, where the version is also reported with the 5.5.5- prefix.

This commit makes an adjustment to wpdb::has_cap() to check for the correct MariaDB version.

This resolves an issue where the utf8mb4_unicode_520_ci collation, which is available in MariaDB since version 10.2, was previously not detected correctly.

References:

Follow-up to [37523], [53919].

Props jamieburchell, SergeyBiryukov.
Fixes #54841.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/db/charset.php

    r53919 r54384  
    4848
    4949                // Account for MariaDB version being prefixed with '5.5.5-' on older PHP versions.
    50                 if ( str_contains( self::$db_server_info, 'MariaDB' ) && '5.5.5' === self::$db_version
     50                if ( '5.5.5' === self::$db_version && str_contains( self::$db_server_info, 'MariaDB' )
    5151                        && PHP_VERSION_ID < 80016 // PHP 8.0.15 or older.
    5252                ) {
     
    11901190                self::$_wpdb->set_charset( self::$_wpdb->dbh );
    11911191        }
     1192
     1193        /**
     1194         * @ticket 54841
     1195         */
     1196        public function test_mariadb_supports_utf8mb4_520() {
     1197                global $wpdb;
     1198
     1199                // utf8mb4_520 is available in MariaDB since version 10.2.
     1200                if ( ! str_contains( self::$db_server_info, 'MariaDB' )
     1201                        || version_compare( self::$db_version, '10.2', '<' )
     1202                ) {
     1203                        $this->markTestSkipped( 'This test requires MariaDB 10.2 or later.' );
     1204                }
     1205
     1206                $this->assertTrue( $wpdb->has_cap( 'utf8mb4_520' ) );
     1207        }
    11921208}
Note: See TracChangeset for help on using the changeset viewer.