diff --git a/src/Doctrine/Functions/Natsort.php b/src/Doctrine/Functions/Natsort.php index fc60058f..56001039 100644 --- a/src/Doctrine/Functions/Natsort.php +++ b/src/Doctrine/Functions/Natsort.php @@ -69,13 +69,36 @@ private function mariaDBSupportsNaturalSort(Connection $connection): bool } $version = $connection->getServerVersion(); - //Remove the -MariaDB suffix - $version = str_replace('-MariaDB', '', $version); + + //Get the effective MariaDB version number + $version = $this->getMariaDbMysqlVersionNumber($version); + //We need at least MariaDB 10.7.0 to support the natural sort self::$supportsNaturalSort = version_compare($version, '10.7.0', '>='); return self::$supportsNaturalSort; } + /** + * Taken from Doctrine\DBAL\Driver\AbstractMySQLDriver + * + * Detect MariaDB server version, including hack for some mariadb distributions + * that starts with the prefix '5.5.5-' + * + * @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial' + */ + private function getMariaDbMysqlVersionNumber(string $versionString) : string + { + if ( ! preg_match( + '/^(?:5\.5\.5-)?(mariadb-)?(?P\d+)\.(?P\d+)\.(?P\d+)/i', + $versionString, + $versionParts + )) { + throw new \RuntimeException('Could not detect MariaDB version from version string ' . $versionString); + } + + return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch']; + } + public function parse(Parser $parser): void { $parser->match(TokenType::T_IDENTIFIER);