Skip to content

Commit

Permalink
Move versionToInt to Query\Utilities
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed May 31, 2020
1 parent 54e27c6 commit eecab19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
14 changes: 1 addition & 13 deletions libraries/classes/DatabaseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -1126,18 +1126,6 @@ public function setVariable(
return $this->query('SET ' . $var . ' = ' . $value . ';', $link);
}

/**
* Convert version string to integer.
*
* @param string $version MySQL server version
*/
public static function versionToInt(string $version): int
{
$match = explode('.', $version);

return (int) sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2]));
}

/**
* Function called just after a connection to the MySQL database server has
* been established. It sets the connection collation, and determines the
Expand All @@ -1153,7 +1141,7 @@ public function postConnect(): void

if (is_array($version)) {
$this->_version_str = $version['@@version'] ?? '';
$this->_version_int = self::versionToInt($this->_version_str);
$this->_version_int = Utilities::versionToInt($this->_version_str);
$this->_version_comment = $version['@@version_comment'] ?? '';
if (stripos($this->_version_str, 'mariadb') !== false) {
$this->_is_mariadb = true;
Expand Down
12 changes: 12 additions & 0 deletions libraries/classes/Query/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,16 @@ public static function usortComparisonCallback(array $a, array $b, string $sortB

return ($sortOrder === 'ASC' ? 1 : -1) * $compare;
}

/**
* Convert version string to integer.
*
* @param string $version MySQL server version
*/
public static function versionToInt(string $version): int
{
$match = explode('.', $version);

return (int) sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2]));
}
}
2 changes: 1 addition & 1 deletion test/classes/DatabaseInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public function isAmazonRdsData()
*/
public function testVersion($version, $expected, $major, $upgrade): void
{
$ver_int = DatabaseInterface::versionToInt($version);
$ver_int = Utilities::versionToInt($version);
$this->assertEquals($expected, $ver_int);
$this->assertEquals($major, (int) ($ver_int / 10000));
$this->assertEquals($upgrade, $ver_int < $GLOBALS['cfg']['MysqlMinVersion']['internal']);
Expand Down

0 comments on commit eecab19

Please sign in to comment.