diff options
author | Peter Zhang <waikatozhang@gmail.com> | 2021-09-22 07:17:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-22 07:17:12 +0300 |
commit | 0adaea428ed8b8b83f08c645ecba3eed4938e2fa (patch) | |
tree | 8bef2b392a738d1e0a0ccc855e349fbe3bbc4f41 | |
parent | 962bd82b8069af16bb5fcfcc7d2ef75731a5bf2e (diff) |
removed Mssql and pgsql (#18042)
-rwxr-xr-x | config/global.ini.php | 2 | ||||
-rw-r--r-- | core/Db/Adapter.php | 7 | ||||
-rw-r--r-- | core/Db/Adapter/Pdo/Mssql.php | 266 | ||||
-rw-r--r-- | core/Db/Adapter/Pdo/Pgsql.php | 183 | ||||
-rw-r--r-- | core/Tracker/Db/Pdo/Pgsql.php | 116 | ||||
-rw-r--r-- | tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png | 4 |
6 files changed, 2 insertions, 576 deletions
diff --git a/config/global.ini.php b/config/global.ini.php index f5f8f49b28..5d18309b0f 100755 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -399,8 +399,6 @@ purge_date_range_archives_after_X_days = 1 ; note: timezone support added in 4.1.3 minimum_mysql_version = 4.1 -; PostgreSQL minimum required version -minimum_pgsql_version = 8.3 ; Minimum advised memory limit in Mb in php.ini file (see memory_limit value) ; Set to "-1" to always use the configured memory_limit value in php.ini file. diff --git a/core/Db/Adapter.php b/core/Db/Adapter.php index 44263a9f50..55d8c4eaef 100644 --- a/core/Db/Adapter.php +++ b/core/Db/Adapter.php @@ -110,13 +110,6 @@ class Adapter 'Mysqli', // other adapters supported by Zend_Db -// 'Pdo_Pgsql', -// 'Pdo_Mssql', -// 'Sqlsrv', -// 'Pdo_Ibm', -// 'Db2', -// 'Pdo_Oci', -// 'Oracle', ); $adapters = array(); diff --git a/core/Db/Adapter/Pdo/Mssql.php b/core/Db/Adapter/Pdo/Mssql.php deleted file mode 100644 index 74d606a2ed..0000000000 --- a/core/Db/Adapter/Pdo/Mssql.php +++ /dev/null @@ -1,266 +0,0 @@ -<?php -/** - * Matomo - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Db\Adapter\Pdo; - -use Exception; -use PDO; -use PDOException; -use Piwik\Config; -use Piwik\Db\AdapterInterface; -use Piwik\Piwik; -use Zend_Db; -use Zend_Db_Adapter_Exception; -use Zend_Db_Adapter_Pdo_Mssql; -use Zend_Db_Profiler; - -/** - */ -class Mssql extends Zend_Db_Adapter_Pdo_Mssql implements AdapterInterface -{ - /** - * Returns connection handle - * - * @throws Zend_Db_Adapter_Exception - * @return resource - */ - public function getConnection() - { - // if we already have a PDO object, no need to re-connect. - if ($this->_connection) { - return $this->_connection; - } - - $this->_pdoType = "sqlsrv"; - // get the dsn first, because some adapters alter the $_pdoType - //$dsn = $this->_dsn(); - - // check for PDO extension - if (!extension_loaded('pdo')) { - /** - * @see Zend_Db_Adapter_Exception - */ - throw new \Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded'); - } - - // check the PDO driver is available - if (!in_array($this->_pdoType, PDO::getAvailableDrivers())) { - /** - * @see Zend_Db_Adapter_Exception - */ - throw new \Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed'); - } - - // create PDO connection - $q = $this->_profiler->queryStart('connect', Zend_Db_Profiler::CONNECT); - - // add the persistence flag if we find it in our config array - if (isset($this->_config['persistent']) && ($this->_config['persistent'] == true)) { - $this->_config['driver_options'][PDO::ATTR_PERSISTENT] = true; - } - - try { - $serverName = $this->_config["host"]; - $database = $this->_config["dbname"]; - if (is_null($database)) { - $database = 'master'; - } - $uid = $this->_config['username']; - $pwd = $this->_config['password']; - if ($this->_config["port"] != "") { - $serverName = $serverName . "," . $this->_config["port"]; - } - - $this->_connection = new PDO("sqlsrv:$serverName", $uid, $pwd, array('Database' => $database)); - - if ($this->_connection === false) { - die(self::FormatErrors(sqlsrv_errors())); - } - - /* - $this->_connection = new PDO( - $dsn, - $this->_config['username'], - $this->_config['password'], - $this->_config['driver_options'] - ); - */ - - $this->_profiler->queryEnd($q); - - // set the PDO connection to perform case-folding on array keys, or not - $this->_connection->setAttribute(PDO::ATTR_CASE, $this->_caseFolding); - $this->_connection->setAttribute(PDO::SQLSRV_ENCODING_UTF8, true); - - // always use exceptions. - $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - return $this->_connection; - } catch (PDOException $e) { - /** - * @see Zend_Db_Adapter_Exception - */ - throw new \Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e); - } - } - - /** - * Reset the configuration variables in this adapter. - */ - public function resetConfig() - { - $this->_config = array(); - } - - /** - * Return default port. - * - * @return int - */ - public static function getDefaultPort() - { - return 1433; - } - - /** - * Check MSSQL version - * - * @throws Exception - */ - public function checkServerVersion() - { - $serverVersion = $this->getServerVersion(); - $requiredVersion = Config::getInstance()->General['minimum_mssql_version']; - - if (version_compare($serverVersion, $requiredVersion) === -1) { - throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MSSQL', $serverVersion, $requiredVersion))); - } - } - - /** - * Returns the Mssql server version - * - * @return null|string - */ - public function getServerVersion() - { - try { - $stmt = $this->query("SELECT CAST(SERVERPROPERTY('productversion') as VARCHAR) as productversion"); - $result = $stmt->fetchAll(Zend_Db::FETCH_NUM); - if (count($result)) { - return $result[0][0]; - } - } catch (PDOException $e) { - } - - return null; - } - - /** - * Check client version compatibility against database server - * - * @throws Exception - */ - public function checkClientVersion() - { - $serverVersion = $this->getServerVersion(); - $clientVersion = $this->getClientVersion(); - - if (version_compare($serverVersion, '10') >= 0 - && version_compare($clientVersion, '10') < 0 - ) { - throw new Exception(Piwik::translate('General_ExceptionIncompatibleClientServerVersions', array('MSSQL', $clientVersion, $serverVersion))); - } - } - - /** - * Returns true if this adapter's required extensions are enabled - * - * @return bool - */ - public static function isEnabled() - { - return extension_loaded('PDO') && extension_loaded('pdo_sqlsrv'); - } - - /** - * Returns true if this adapter supports blobs as fields - * - * @return bool - */ - public function hasBlobDataType() - { - return true; - } - - /** - * Returns true if this adapter supports bulk loading - * - * @return bool - */ - public function hasBulkLoader() - { - /** - * BULK INSERT doesn't have a way to escape a terminator that appears in a value - * - * @link http://msdn.microsoft.com/en-us/library/ms188365.aspx - */ - return false; - } - - /** - * Test error number - * - * @param Exception $e - * @param string $errno - * @return bool - */ - public function isErrNo($e, $errno) - { - if (preg_match('/(?:\[|\s)([0-9]{4})(?:\]|\s)/', $e->getMessage(), $match)) { - return $match[1] == $errno; - } - - return false; - } - - /** - * Is the connection character set equal to utf8? - * - * @return bool - */ - public function isConnectionUTF8() - { - //check the getconnection, it's specified on the connection string. - return true; - } - - /** - * Retrieve client version in PHP style - * - * @throws Exception - * @return string - */ - public function getClientVersion() - { - $this->_connect(); - try { - $version = $this->_connection->getAttribute(PDO::ATTR_CLIENT_VERSION); - $requiredVersion = Config::getInstance()->General['minimum_mssql_client_version']; - if (version_compare($version['DriverVer'], $requiredVersion) === -1) { - throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MSSQL', $version['DriverVer'], $requiredVersion))); - } else { - return $version['DriverVer']; - } - } catch (PDOException $e) { - // In case of the driver doesn't support getting attributes - } - - return null; - } -} diff --git a/core/Db/Adapter/Pdo/Pgsql.php b/core/Db/Adapter/Pdo/Pgsql.php deleted file mode 100644 index ac9f527f47..0000000000 --- a/core/Db/Adapter/Pdo/Pgsql.php +++ /dev/null @@ -1,183 +0,0 @@ -<?php -/** - * Matomo - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Db\Adapter\Pdo; - -use Exception; -use PDO; -use PDOException; -use Piwik\Config; -use Piwik\Db\AdapterInterface; -use Piwik\Piwik; -use Zend_Db_Adapter_Pdo_Pgsql; - -/** - */ -class Pgsql extends Zend_Db_Adapter_Pdo_Pgsql implements AdapterInterface -{ - /** - * Reset the configuration variables in this adapter. - */ - public function resetConfig() - { - $this->_config = array(); - } - - /** - * Return default port. - * - * @return int - */ - public static function getDefaultPort() - { - return 5432; - } - - /** - * Check PostgreSQL version - * - * @throws Exception - */ - public function checkServerVersion() - { - $databaseVersion = $this->getServerVersion(); - $requiredVersion = Config::getInstance()->General['minimum_pgsql_version']; - - if (version_compare($databaseVersion, $requiredVersion) === -1) { - throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('PostgreSQL', $databaseVersion, $requiredVersion))); - } - } - - /** - * Check client version compatibility against database server - */ - public function checkClientVersion() - { - } - - /** - * Returns true if this adapter's required extensions are enabled - * - * @return bool - */ - public static function isEnabled() - { - return extension_loaded('PDO') && extension_loaded('pdo_pgsql'); - } - - /** - * Returns true if this adapter supports blobs as fields - * - * @return bool - */ - public function hasBlobDataType() - { - // large objects must be loaded from a file using a non-SQL API - // and then referenced by the object ID (oid); - // the alternative, bytea fields, incur a space and time - // penalty for encoding/decoding - return false; - } - - /** - * Returns true if this adapter supports bulk loading - * - * @return bool - */ - public function hasBulkLoader() - { - /** - * COPY ? - * - * @link http://www.postgresql.org/docs/current/interactive/sql-copy.html - */ - return false; - } - - /** - * Test error number - * - * @param Exception $e - * @param string $errno - * @return bool - */ - public function isErrNo($e, $errno) - { - // map MySQL driver-specific error codes to PostgreSQL SQLSTATE - $map = array( - // MySQL: Unknown database '%s' - // PostgreSQL: database "%s" does not exist - '1049' => '08006', - - // MySQL: Table '%s' already exists - // PostgreSQL: relation "%s" already exists - '1050' => '42P07', - - // MySQL: Unknown column '%s' in '%s' - // PostgreSQL: column "%s" does not exist - '1054' => '42703', - - // MySQL: Duplicate column name '%s' - // PostgreSQL: column "%s" of relation "%s" already exists - '1060' => '42701', - - // MySQL: Duplicate key name '%s' - // PostgreSQL: relation "%s" already exists - '1061' => '42P07', - - // MySQL: Duplicate entry '%s' for key '%s' - // PostgreSQL: duplicate key violates unique constraint - '1062' => '23505', - - // MySQL: Can't DROP '%s'; check that column/key exists - // PostgreSQL: index "%s" does not exist - '1091' => '42704', - - // MySQL: Table '%s.%s' doesn't exist - // PostgreSQL: relation "%s" does not exist - '1146' => '42P01', - ); - - if (preg_match('/([0-9]{2}[0-9P][0-9]{2})/', $e->getMessage(), $match)) { - return $match[1] == $map[$errno]; - } - - return false; - } - - /** - * Is the connection character set equal to utf8? - * - * @return bool - */ - public function isConnectionUTF8() - { - $charset = $this->fetchOne('SHOW client_encoding'); - return strpos(strtolower($charset), 'utf8') === 0; - } - - /** - * Retrieve client version in PHP style - * - * @return string - */ - public function getClientVersion() - { - $this->_connect(); - try { - $version = $this->_connection->getAttribute(PDO::ATTR_CLIENT_VERSION); - $matches = null; - if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) { - return $matches[1]; - } - } catch (PDOException $e) { - // In case of the driver doesn't support getting attributes - } - return null; - } -} diff --git a/core/Tracker/Db/Pdo/Pgsql.php b/core/Tracker/Db/Pdo/Pgsql.php deleted file mode 100644 index 967c8909e1..0000000000 --- a/core/Tracker/Db/Pdo/Pgsql.php +++ /dev/null @@ -1,116 +0,0 @@ -<?php -/** - * Matomo - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ - -namespace Piwik\Tracker\Db\Pdo; - -use Exception; -use PDO; - -/** - * PDO PostgreSQL wrapper - * - */ -class Pgsql extends Mysql -{ - /** - * Builds the DB object - * - * @param array $dbInfo - * @param string $driverName - */ - public function __construct($dbInfo, $driverName = 'pgsql') - { - parent::__construct($dbInfo, $driverName); - } - - /** - * Connects to the DB - * - * @throws Exception if there was an error connecting the DB - */ - public function connect() - { - if (self::$profiling) { - $timer = $this->initProfiler(); - } - - $this->connection = new PDO($this->dsn, $this->username, $this->password, $config = array()); - $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - // we may want to setAttribute(PDO::ATTR_TIMEOUT ) to a few seconds (default is 60) in case the DB is locked - // the matomo.php would stay waiting for the database... bad! - // we delete the password from this object "just in case" it could be printed - $this->password = ''; - - if (!empty($this->charset)) { - $sql = "SET NAMES '" . $this->charset . "'"; - $this->connection->exec($sql); - } - - if (self::$profiling && isset($timer)) { - $this->recordQueryProfile('connect', $timer); - } - } - - /** - * Test error number - * - * @param Exception $e - * @param string $errno - * @return bool - */ - public function isErrNo($e, $errno) - { - // map MySQL driver-specific error codes to PostgreSQL SQLSTATE - $map = array( - // MySQL: Unknown database '%s' - // PostgreSQL: database "%s" does not exist - '1049' => '08006', - - // MySQL: Table '%s' already exists - // PostgreSQL: relation "%s" already exists - '1050' => '42P07', - - // MySQL: Unknown column '%s' in '%s' - // PostgreSQL: column "%s" does not exist - '1054' => '42703', - - // MySQL: Duplicate column name '%s' - // PostgreSQL: column "%s" of relation "%s" already exists - '1060' => '42701', - - // MySQL: Duplicate entry '%s' for key '%s' - // PostgreSQL: duplicate key violates unique constraint - '1062' => '23505', - - // MySQL: Can't DROP '%s'; check that column/key exists - // PostgreSQL: index "%s" does not exist - '1091' => '42704', - - // MySQL: Table '%s.%s' doesn't exist - // PostgreSQL: relation "%s" does not exist - '1146' => '42P01', - ); - - if (preg_match('/([0-9]{2}[0-9P][0-9]{2})/', $e->getMessage(), $match)) { - return $match[1] == $map[$errno]; - } - return false; - } - - /** - * Return number of affected rows in last query - * - * @param mixed $queryResult Result from query() - * @return int - */ - public function rowCount($queryResult) - { - return $queryResult->rowCount(); - } -} diff --git a/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png b/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png index 633b14c135..72b1cdc6c7 100644 --- a/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png +++ b/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:45c430b9702f74fe073718aab63746747dfc20ad97bca071d74ca3162e121d35 -size 5251676 +oid sha256:9ce587e169c99f1a42a2d68c882b9cdc76079e2b62aed02a6f639bc8cfd00c11 +size 5246106 |