Skip to content

Commit

Permalink
Correctly identify whether MariaDB supports utf8mb4_520
Browse files Browse the repository at this point in the history
In older versions of PHP `$db_version` will be `5.5.5` for MariaDB, which prevents the use of the `utf8mb4_unicode_520_ci` collation.

See https://core.trac.wordpress.org/changeset/54384
  • Loading branch information
dd32 authored May 8, 2024
1 parent d8f68ef commit f6b2f99
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions db.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,22 +1102,33 @@ public function supports_collation( $dbh_or_table = false ) {
/**
* Generic function to determine if a database supports a particular feature
* The additional argument allows the caller to check a specific database.
*

Check failure on line 1105 in db.php

View workflow job for this annotation

GitHub Actions / Run code style check

Tabs must be used to indent lines; spaces are not allowed
* @param string $db_cap the feature
* @param false|string|resource $dbh_or_table the databaese (the current database, the database housing the specified table, or the database of the mysql resource)
* @return bool
*/
public function has_cap( $db_cap, $dbh_or_table = false ) {
$version = $this->db_version( $dbh_or_table );
$db_version = $this->db_version( $dbh_or_table );
$db_server_info = $this->db_server_info( $dbh_or_table );

// Account for MariaDB version being prefixed with '5.5.5-' on older PHP versions.
if ( '5.5.5' === $db_version && false !== strpos( $db_server_info, 'MariaDB' )
&& PHP_VERSION_ID < 80016 // PHP 8.0.15 or older.
) {
// Strip the '5.5.5-' prefix and set the version to the correct value.
$db_server_info = preg_replace( '/^5\.5\.5-(.*)/', '$1', $db_server_info );
$db_version = preg_replace( '/[^0-9.].*/', '', $db_server_info );
}

switch ( strtolower( $db_cap ) ) :
case 'collation':
case 'group_concat':
case 'subqueries':
return version_compare( $version, '4.1', '>=' );
return version_compare( $db_version, '4.1', '>=' );
case 'set_charset':
return version_compare( $version, '5.0.7', '>=' );
return version_compare( $db_version, '5.0.7', '>=' );
case 'utf8mb4': // @since WP 4.1.0
if ( version_compare( $version, '5.5.3', '<' ) ) {
if ( version_compare( $db_version, '5.5.3', '<' ) ) {
return false;
}
if ( $this->use_mysqli ) {
Expand All @@ -1137,7 +1148,7 @@ public function has_cap( $db_cap, $dbh_or_table = false ) {
return version_compare( $client_version, '5.5.3', '>=' );
}
case 'utf8mb4_520': // since WP 4.6
return $this->has_cap( 'utf8mb4', $dbh_or_table ) && version_compare( $version, '5.6', '>=' );
return $this->has_cap( 'utf8mb4', $dbh_or_table ) && version_compare( $db_version, '5.6', '>=' );
endswitch;

return false;
Expand Down

0 comments on commit f6b2f99

Please sign in to comment.