Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core/Db
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-07-23 11:52:15 +0400
committermattab <matthieu.aubry@gmail.com>2013-07-23 11:52:15 +0400
commit5104d94f3b2250f766b9c520e2da8da9b4cab2e9 (patch)
tree5f30daf7bc14373fb1bbd0504ce11a771dafc02f /core/Db
parentae4b1f4e38077b174e4df5b7d4513d63fe026a24 (diff)
Refs #4059 Work in progress: Conversion to use Namespaces of dozen more classes
Removed many Piwik_ functions, in Piwik 2 it is best practise to use the methods calls instead Todo: finish converting core/ classes + convert plugins/ classes to use \Piwik\Plugin namespace + fix build + Merge master
Diffstat (limited to 'core/Db')
-rw-r--r--core/Db/Adapter.php8
-rw-r--r--core/Db/Adapter/Mysqli.php3
-rw-r--r--core/Db/Adapter/Pdo/Mssql.php21
-rw-r--r--core/Db/Adapter/Pdo/Mysql.php12
-rw-r--r--core/Db/Adapter/Pdo/Pgsql.php9
-rw-r--r--core/Db/AdapterInterface.php (renamed from core/Db/Adapter/Interface.php)6
-rw-r--r--core/Db/Schema.php15
-rw-r--r--core/Db/Schema/Myisam.php25
-rw-r--r--core/Db/SchemaInterface.php (renamed from core/Db/Schema/Interface.php)4
9 files changed, 73 insertions, 30 deletions
diff --git a/core/Db/Adapter.php b/core/Db/Adapter.php
index db9214b82a..e818866802 100644
--- a/core/Db/Adapter.php
+++ b/core/Db/Adapter.php
@@ -8,13 +8,17 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\Db;
+
+use Piwik\Db\AdapterInterface;
use Piwik\Loader;
+use Zend_Db_Table;
/**
* @package Piwik
* @subpackage Piwik_Db
*/
-class Piwik_Db_Adapter
+class Adapter
{
/**
* Create adapter
@@ -22,7 +26,7 @@ class Piwik_Db_Adapter
* @param string $adapterName database adapter name
* @param array $dbInfos database connection info
* @param bool $connect
- * @return Piwik_Db_Adapter_Interface
+ * @return AdapterInterface
*/
public static function factory($adapterName, & $dbInfos, $connect = true)
{
diff --git a/core/Db/Adapter/Mysqli.php b/core/Db/Adapter/Mysqli.php
index 38495a2357..db923dbf99 100644
--- a/core/Db/Adapter/Mysqli.php
+++ b/core/Db/Adapter/Mysqli.php
@@ -9,12 +9,13 @@
* @package Piwik
*/
use Piwik\Config;
+use Piwik\Db\AdapterInterface;
/**
* @package Piwik
* @subpackage Piwik_Db
*/
-class Piwik_Db_Adapter_Mysqli extends Zend_Db_Adapter_Mysqli implements Piwik_Db_Adapter_Interface
+class Piwik_Db_Adapter_Mysqli extends Zend_Db_Adapter_Mysqli implements AdapterInterface
{
/**
* Constructor
diff --git a/core/Db/Adapter/Pdo/Mssql.php b/core/Db/Adapter/Pdo/Mssql.php
index 458a99fcc5..c77797b6c1 100644
--- a/core/Db/Adapter/Pdo/Mssql.php
+++ b/core/Db/Adapter/Pdo/Mssql.php
@@ -8,13 +8,23 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\Db\Adapter\Pdo;
+
+use Exception;
+use PDO;
+use PDOException;
use Piwik\Config;
+use Piwik\Db\Adapter\AdapterInterface;
+use Zend_Db;
+use Zend_Db_Adapter_Exception;
+use Zend_Db_Adapter_Pdo_Mssql;
+use Zend_Db_Profiler;
/**
* @package Piwik
* @subpackage Piwik_Db
*/
-class Piwik_Db_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql implements Piwik_Db_Adapter_Interface
+class Mssql extends Zend_Db_Adapter_Pdo_Mssql implements AdapterInterface
{
/**
* Returns connection handle
@@ -38,7 +48,7 @@ class Piwik_Db_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql implements Piwik_Db_A
/**
* @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');
+ 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
@@ -46,7 +56,7 @@ class Piwik_Db_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql implements Piwik_Db_A
/**
* @see Zend_Db_Adapter_Exception
*/
- throw new Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed');
+ throw new \Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed');
}
// create PDO connection
@@ -71,7 +81,6 @@ class Piwik_Db_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql implements Piwik_Db_A
$this->_connection = new PDO("sqlsrv:$serverName", $uid, $pwd, array('Database' => $database));
-
if ($this->_connection === false) {
die(self::FormatErrors(sqlsrv_errors()));
}
@@ -91,7 +100,6 @@ class Piwik_Db_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql implements Piwik_Db_A
$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);
@@ -100,7 +108,7 @@ class Piwik_Db_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql implements Piwik_Db_A
/**
* @see Zend_Db_Adapter_Exception
*/
- throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
+ throw new \Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
}
}
@@ -134,7 +142,6 @@ class Piwik_Db_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql implements Piwik_Db_A
if (version_compare($serverVersion, $requiredVersion) === -1) {
throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MSSQL', $serverVersion, $requiredVersion)));
}
-
}
/**
diff --git a/core/Db/Adapter/Pdo/Mysql.php b/core/Db/Adapter/Pdo/Mysql.php
index c2ad0ea2d8..37dae1bee8 100644
--- a/core/Db/Adapter/Pdo/Mysql.php
+++ b/core/Db/Adapter/Pdo/Mysql.php
@@ -8,13 +8,23 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\Db\Adapter\Pdo;
+
+use Exception;
+use PDO;
+use PDOException;
use Piwik\Config;
+use Piwik\Db\Adapter\AdapterInterface;
+use Zend_Config;
+use Zend_Db_Adapter_Pdo_Mysql;
+use Zend_Db_Select;
+use Zend_Db_Statement_Interface;
/**
* @package Piwik
* @subpackage Piwik_Db
*/
-class Piwik_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Mysql implements Piwik_Db_Adapter_Interface
+class Mysql extends Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
{
/**
* Constructor
diff --git a/core/Db/Adapter/Pdo/Pgsql.php b/core/Db/Adapter/Pdo/Pgsql.php
index f4e68dfde9..16baba2543 100644
--- a/core/Db/Adapter/Pdo/Pgsql.php
+++ b/core/Db/Adapter/Pdo/Pgsql.php
@@ -8,13 +8,20 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\Db\Adapter\Pdo;
+
+use Exception;
+use PDO;
+use PDOException;
use Piwik\Config;
+use Piwik\Db\Adapter\AdapterInterface;
+use Zend_Db_Adapter_Pdo_Pgsql;
/**
* @package Piwik
* @subpackage Piwik_Db
*/
-class Piwik_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Pgsql implements Piwik_Db_Adapter_Interface
+class Pgsql extends Zend_Db_Adapter_Pdo_Pgsql implements AdapterInterface
{
/**
* Reset the configuration variables in this adapter.
diff --git a/core/Db/Adapter/Interface.php b/core/Db/AdapterInterface.php
index bd81c0834d..e13a99769b 100644
--- a/core/Db/Adapter/Interface.php
+++ b/core/Db/AdapterInterface.php
@@ -9,11 +9,15 @@
* @package Piwik
*/
+namespace Piwik\Db;
+
+use Exception;
+
/**
* @package Piwik
* @subpackage Piwik_Db
*/
-interface Piwik_Db_Adapter_Interface
+interface AdapterInterface
{
/**
* Reset the configuration variables in this adapter.
diff --git a/core/Db/Schema.php b/core/Db/Schema.php
index fed20dfe28..261860c6a1 100644
--- a/core/Db/Schema.php
+++ b/core/Db/Schema.php
@@ -8,7 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\Db;
+
use Piwik\Config;
+use Piwik\Db\Schema\SchemaInterface;
/**
* Schema abstraction
@@ -18,12 +21,12 @@ use Piwik\Config;
* @package Piwik
* @subpackage Piwik_Db
*/
-class Piwik_Db_Schema
+class Schema
{
/**
* Singleton instance
*
- * @var Piwik_Db_Schema
+ * @var \Piwik\Db\Schema
*/
static private $instance = null;
@@ -35,9 +38,9 @@ class Piwik_Db_Schema
private $schema = null;
/**
- * Returns the singleton Piwik_Db_Schema
+ * Returns the singleton Schema
*
- * @return Piwik_Db_Schema
+ * @return \Piwik\Db\Schema
*/
static public function getInstance()
{
@@ -145,9 +148,9 @@ class Piwik_Db_Schema
}
/**
- * Returns an instance that subclasses Piwik_Db_Schema
+ * Returns an instance that subclasses Schema
*
- * @return Piwik_Db_Schema_Interface
+ * @return \Piwik\Db\Schema\SchemaInterface
*/
private function getSchema()
{
diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Myisam.php
index 274e6f82e0..8a6ae12e07 100644
--- a/core/Db/Schema/Myisam.php
+++ b/core/Db/Schema/Myisam.php
@@ -8,10 +8,15 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\Db\Schema;
+
+use Exception;
use Piwik\Config;
+use Piwik\Db\Schema\SchemaInterface;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Date;
+use Zend_Registry;
/**
* MySQL schema
@@ -19,7 +24,7 @@ use Piwik\Date;
* @package Piwik
* @subpackage Piwik_Db
*/
-class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
+class Myisam implements SchemaInterface
{
/**
* Is this MySQL storage engine available?
@@ -92,7 +97,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
excluded_ips TEXT NOT NULL,
excluded_parameters TEXT NOT NULL,
excluded_user_agents TEXT NOT NULL,
- `group` VARCHAR(250) NOT NULL,
+ `group` VARCHAR(250) NOT NULL,
keep_url_fragment TINYINT NOT NULL DEFAULT 0,
PRIMARY KEY(idsite)
) DEFAULT CHARSET=utf8
@@ -197,7 +202,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
visit_total_searches SMALLINT(5) UNSIGNED NOT NULL,
visit_total_time SMALLINT(5) UNSIGNED NOT NULL,
visit_goal_converted TINYINT(1) NOT NULL,
- visit_goal_buyer TINYINT(1) NOT NULL,
+ visit_goal_buyer TINYINT(1) NOT NULL,
referer_type TINYINT(1) UNSIGNED NULL,
referer_name VARCHAR(70) NULL,
referer_url TEXT NOT NULL,
@@ -247,7 +252,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
server_time DATETIME NOT NULL,
idvisit INTEGER(10) UNSIGNED NOT NULL,
idorder varchar(100) NOT NULL,
-
+
idaction_sku INTEGER(10) UNSIGNED NOT NULL,
idaction_name INTEGER(10) UNSIGNED NOT NULL,
idaction_category INTEGER(10) UNSIGNED NOT NULL,
@@ -258,7 +263,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
price FLOAT NOT NULL,
quantity INTEGER(10) UNSIGNED NOT NULL,
deleted TINYINT(1) UNSIGNED NOT NULL,
-
+
PRIMARY KEY(idvisit, idorder, idaction_sku),
INDEX index_idsite_servertime ( idsite, server_time )
) DEFAULT CHARSET=utf8
@@ -287,7 +292,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
url text NOT NULL,
idgoal int(10) NOT NULL,
buster int unsigned NOT NULL,
-
+
idorder varchar(100) default NULL,
items SMALLINT UNSIGNED DEFAULT NULL,
revenue float default NULL,
@@ -295,7 +300,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
revenue_tax float default NULL,
revenue_shipping float default NULL,
revenue_discount float default NULL,
-
+
custom_var_k1 VARCHAR(200) DEFAULT NULL,
custom_var_v1 VARCHAR(200) DEFAULT NULL,
custom_var_k2 VARCHAR(200) DEFAULT NULL,
@@ -493,7 +498,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
if (is_null($dbName)) {
$dbName = Config::getInstance()->database['dbname'];
}
- Piwik_Exec("CREATE DATABASE IF NOT EXISTS " . $dbName . " DEFAULT CHARACTER SET utf8");
+ Db::exec("CREATE DATABASE IF NOT EXISTS " . $dbName . " DEFAULT CHARACTER SET utf8");
}
/**
@@ -502,7 +507,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
public function dropDatabase()
{
$dbName = Config::getInstance()->database['dbname'];
- Piwik_Exec("DROP DATABASE IF EXISTS " . $dbName);
+ Db::exec("DROP DATABASE IF EXISTS " . $dbName);
}
/**
@@ -546,7 +551,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
{
$tablesAlreadyInstalled = $this->getTablesInstalled($forceReload = true);
foreach ($tablesAlreadyInstalled as $table) {
- Piwik_Query("TRUNCATE `$table`");
+ Db::query("TRUNCATE `$table`");
}
}
diff --git a/core/Db/Schema/Interface.php b/core/Db/SchemaInterface.php
index a56f79eb03..c8ad0eb340 100644
--- a/core/Db/Schema/Interface.php
+++ b/core/Db/SchemaInterface.php
@@ -9,13 +9,15 @@
* @package Piwik
*/
+namespace Piwik\Db;
+
/**
* Database schema interface
*
* @package Piwik
* @subpackage Piwik_Db
*/
-interface Piwik_Db_Schema_Interface
+interface SchemaInterface
{
/**
* Is this schema available?