Skip to content

Commit

Permalink
Fixes matomo-org#12002 and matomo-org#12030 - azure fallback to "sele…
Browse files Browse the repository at this point in the history
…ct @@Version"
  • Loading branch information
robocoder committed Mar 24, 2018
1 parent d9eef2a commit e8fbfc9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions core/Db/Adapter/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,24 @@ public function checkServerVersion()
$serverVersion = $this->getServerVersion();
$requiredVersion = Config::getInstance()->General['minimum_mysql_version'];

if (version_compare($serverVersion, $requiredVersion) === -1) {
throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
if (version_compare($serverVersion, $requiredVersion) >= 0) {
return;
}

// Azure lies/misreports the MySQL version in the connection handshake
if (isset($this->_config['host']) && strpos($this->_config['host'], '.mysql.database.azure.com') !== false) {
$versionInfo = $this->fetchAll('SELECT @@VERSION');

if (count($versionInfo)) {
$serverVersion = $versionInfo[0]['@@VERSION'];

if (version_compare($serverVersion, $requiredVersion) >= 0) {
return;
}
}
}

throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
}

/**
Expand Down
19 changes: 17 additions & 2 deletions core/Db/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,24 @@ public function checkServerVersion()
$serverVersion = $this->getServerVersion();
$requiredVersion = Config::getInstance()->General['minimum_mysql_version'];

if (version_compare($serverVersion, $requiredVersion) === -1) {
throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
if (version_compare($serverVersion, $requiredVersion) >= 0) {
return;
}

// Azure lies/misreports the MySQL version in the connection handshake
if (isset($this->_config['host']) && strpos($this->_config['host'], '.mysql.database.azure.com') !== false) {
$versionInfo = $this->fetchAll('SELECT @@VERSION');

if (count($versionInfo)) {
$serverVersion = $versionInfo[0]['@@VERSION'];

if (version_compare($serverVersion, $requiredVersion) >= 0) {
return;
}
}
}

throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
}

/**
Expand Down

0 comments on commit e8fbfc9

Please sign in to comment.