From 704d6b94c6869455040205c4d7861f9a94266bee Mon Sep 17 00:00:00 2001 From: Anthon Pang Date: Sun, 11 Feb 2018 21:48:14 -0500 Subject: [PATCH] Fixes #12002 and #12030 - azure fallback to "select @@version" --- core/Db/Adapter/Mysqli.php | 19 +++++++++++++++++-- core/Db/Adapter/Pdo/Mysql.php | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/core/Db/Adapter/Mysqli.php b/core/Db/Adapter/Mysqli.php index 396ab6034309..a5b66e710643 100644 --- a/core/Db/Adapter/Mysqli.php +++ b/core/Db/Adapter/Mysqli.php @@ -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))); } /** diff --git a/core/Db/Adapter/Pdo/Mysql.php b/core/Db/Adapter/Pdo/Mysql.php index 360e6a57e8e0..f7f790661775 100644 --- a/core/Db/Adapter/Pdo/Mysql.php +++ b/core/Db/Adapter/Pdo/Mysql.php @@ -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))); } /**