Skip to content

Commit

Permalink
Fixed detection on mariadb natsort capabilities on distributions whic…
Browse files Browse the repository at this point in the history
…h use the 5.5.5- prefix for MariaDB version
  • Loading branch information
jbtronics committed Jun 23, 2024
1 parent 22e2480 commit 19e5d30
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/Doctrine/Functions/Natsort.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\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);
Expand Down

0 comments on commit 19e5d30

Please sign in to comment.