From 19e5d302f488b6fc60f002a73c442685ddda44c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 23 Jun 2024 21:13:37 +0200 Subject: [PATCH] Fixed detection on mariadb natsort capabilities on distributions which use the 5.5.5- prefix for MariaDB version --- src/Doctrine/Functions/Natsort.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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);