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
diff options
context:
space:
mode:
authorBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-24 06:58:51 +0400
committerBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-24 06:58:51 +0400
commit48681dd582fbc9f840183cad28cc3e4dd3418d05 (patch)
tree88008786b75c8a3a342f6e784413430a9c0779e2
parentae5fc3786a19f67202e2e83fd83e9e67657e8173 (diff)
Remove use of Zend_Registry to hold DB connections.
-rw-r--r--core/API/Proxy.php15
-rw-r--r--core/ArchiveProcessor.php4
-rw-r--r--core/DataAccess/ArchiveTableCreator.php4
-rw-r--r--core/DataAccess/ArchiveWriter.php4
-rw-r--r--core/DataAccess/LogAggregator.php4
-rw-r--r--core/Db.php52
-rw-r--r--core/Db/BatchInsert.php5
-rw-r--r--core/Db/Schema/Myisam.php11
-rw-r--r--core/DbHelper.php31
-rw-r--r--core/FrontController.php2
-rw-r--r--core/Log.php2
-rw-r--r--core/Profiler.php6
-rw-r--r--core/Session.php3
-rw-r--r--core/Tracker.php4
-rw-r--r--core/Updater.php4
-rw-r--r--plugins/Dashboard/Dashboard.php3
-rw-r--r--plugins/DevicesDetection/DevicesDetection.php3
-rw-r--r--plugins/Goals/API.php4
-rw-r--r--plugins/Installation/Controller.php4
-rw-r--r--plugins/Installation/FormDatabaseSetup.php9
-rw-r--r--plugins/LanguagesManager/LanguagesManager.php3
-rw-r--r--plugins/PDFReports/API.php8
-rw-r--r--plugins/PDFReports/PDFReports.php3
-rw-r--r--plugins/Provider/Provider.php3
-rw-r--r--plugins/SegmentEditor/API.php11
-rw-r--r--plugins/SegmentEditor/SegmentEditor.php3
-rw-r--r--plugins/SitesManager/API.php38
-rw-r--r--plugins/UsersManager/API.php26
-rw-r--r--tests/PHPUnit/DatabaseTestCase.php5
-rwxr-xr-xtests/PHPUnit/IntegrationTestCase.php4
30 files changed, 131 insertions, 147 deletions
diff --git a/core/API/Proxy.php b/core/API/Proxy.php
index 981452f41f..bfaf1fdac4 100644
--- a/core/API/Proxy.php
+++ b/core/API/Proxy.php
@@ -15,7 +15,6 @@ use Piwik\Common;
use Piwik\Timer;
use ReflectionClass;
use ReflectionMethod;
-use Zend_Registry;
/**
* Proxy is a singleton that has the knowledge of every method available, their parameters
@@ -198,20 +197,6 @@ class Proxy
// Restore the request
$_GET = $saveGET;
$_SERVER['QUERY_STRING'] = $saveQUERY_STRING;
-
- // log the API Call
- try {
- \Zend_Registry::get('logger_api_call')->logEvent(
- $className,
- $methodName,
- $parameterNamesDefaultValues,
- $finalParameters,
- $timer->getTimeMs(),
- $returnedValue
- );
- } catch (Exception $e) {
- // logger can fail (eg. Tracker request)
- }
} catch (Exception $e) {
$_GET = $saveGET;
throw $e;
diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php
index a9b689e468..74ec976335 100644
--- a/core/ArchiveProcessor.php
+++ b/core/ArchiveProcessor.php
@@ -17,10 +17,10 @@ use Piwik\Piwik;
use Piwik\Date;
use Piwik\Segment;
use Piwik\Site;
+use Piwik\Db;
use Piwik\DataAccess\ArchiveSelector;
use Piwik\DataAccess\ArchiveWriter;
use Piwik\DataAccess\LogAggregator;
-use Zend_Registry;
/**
* The ArchiveProcessor class is used by the Archive object to make sure the given Archive is processed and available in the DB.
@@ -424,7 +424,7 @@ abstract class ArchiveProcessor
protected function compress($data)
{
- if (Zend_Registry::get('db')->hasBlobDataType()) {
+ if (Db::get()->hasBlobDataType()) {
return gzcompress($data);
}
return $data;
diff --git a/core/DataAccess/ArchiveTableCreator.php b/core/DataAccess/ArchiveTableCreator.php
index 16fe7d2a23..d6681fa5ae 100644
--- a/core/DataAccess/ArchiveTableCreator.php
+++ b/core/DataAccess/ArchiveTableCreator.php
@@ -15,7 +15,7 @@ use Exception;
use Piwik\Common;
use Piwik\Date;
use Piwik\DbHelper;
-use Zend_Registry;
+use Piwik\Db;
class ArchiveTableCreator
{
@@ -51,7 +51,7 @@ class ArchiveTableCreator
}
if (!in_array($tableName, self::$tablesAlreadyInstalled)) {
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$sql = DbHelper::getTableCreateSql($tableNamePrefix);
// replace table name template by real name
diff --git a/core/DataAccess/ArchiveWriter.php b/core/DataAccess/ArchiveWriter.php
index e6070ae958..a3a11a68f5 100644
--- a/core/DataAccess/ArchiveWriter.php
+++ b/core/DataAccess/ArchiveWriter.php
@@ -87,7 +87,7 @@ class ArchiveWriter
$numericTable = $this->getTableNumeric();
$idSite = $this->idSite;
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$locked = self::PREFIX_SQL_LOCK . Common::generateUniqId();
$date = date("Y-m-d H:i:s");
$dbLockName = "allocateNewArchiveId.$numericTable";
@@ -108,7 +108,7 @@ class ArchiveWriter
try { // TODO: this is temporary, remove when deadlocking issue is fixed
$db->exec($insertSql);
} catch (Exception $ex) {
- if (\Zend_Registry::get('db')->isErrNo($ex, 1213)) {
+ if (Db::get()->isErrNo($ex, 1213)) {
$deadlockInfo = \Piwik\Db::fetchAll("SHOW ENGINE INNODB STATUS");
Piwik::log("DEADLOCK INFO: " . print_r($deadlockInfo));
}
diff --git a/core/DataAccess/LogAggregator.php b/core/DataAccess/LogAggregator.php
index afc262529f..d2aa52f014 100644
--- a/core/DataAccess/LogAggregator.php
+++ b/core/DataAccess/LogAggregator.php
@@ -17,8 +17,8 @@ use Piwik\Date;
use Piwik\Segment;
use Piwik\Site;
use Piwik\RankingQuery;
+use Piwik\Db;
use Piwik\Tracker\GoalManager;
-use Zend_Registry;
/**
* This class queries the Visitor logs tables (visits, actions, conversions, ecommerce)
@@ -518,6 +518,6 @@ class LogAggregator
public function getDb()
{
- return \Zend_Registry::get('db');
+ return Db::get();
}
}
diff --git a/core/Db.php b/core/Db.php
index 223a2a6639..ef2f756f9d 100644
--- a/core/Db.php
+++ b/core/Db.php
@@ -9,8 +9,11 @@
* @package PluginsFunctions
*/
namespace Piwik;
+
use Exception;
+use Piwik\Db\Adapter;
use Piwik\Tracker;
+use Piwik\Config;
/**
* SQL wrapper
@@ -19,24 +22,51 @@ use Piwik\Tracker;
*/
class Db
{
+ private static $connection = null;
+
/**
* Returns the database adapter to use
*
* @return \Piwik\Tracker\Db|\Piwik\Db\AdapterInterface
*/
- static private function getDb()
+ static public function get()
{
$db = null;
if (!empty($GLOBALS['PIWIK_TRACKER_MODE'])) {
$db = Tracker::getDatabase();
}
if ($db === null) {
- $db = \Zend_Registry::get('db');
+ $db = self::$connection;
}
return $db;
}
/**
+ * Create database object and connect to database
+ * @param array|null $dbInfos
+ */
+ public static function createDatabaseObject($dbInfos = null)
+ {
+ $config = Config::getInstance();
+
+ if (is_null($dbInfos)) {
+ $dbInfos = $config->database;
+ }
+
+ Piwik_PostEvent('Reporting.getDatabaseConfig', array(&$dbInfos));
+
+ $dbInfos['profiler'] = $config->Debug['enable_sql_profiler'];
+
+ $db = null;
+ Piwik_PostEvent('Reporting.createDatabase', array(&$db));
+ if (is_null($db)) {
+ $adapter = $dbInfos['adapter'];
+ $db = @Adapter::factory($adapter, $dbInfos);
+ }
+ self::$connection = $db;
+ }
+
+ /**
* Executes an unprepared SQL query on the DB. Recommended for DDL statements, e.g., CREATE/DROP/ALTER.
* The return result is DBMS-specific. For MySQLI, it returns the number of rows affected. For PDO, it returns the Zend_Db_Statement object
* If you want to fetch data from the DB you should use the function Db::fetchAll()
@@ -47,10 +77,10 @@ class Db
static public function exec($sql)
{
/** @var \Zend_Db_Adapter_Abstract $db */
- $db = \Zend_Registry::get('db');
+ $db = self::get();
$profiler = $db->getProfiler();
$q = $profiler->queryStart($sql, \Zend_Db_Profiler::INSERT);
- $return = self::getDb()->exec($sql);
+ $return = self::get()->exec($sql);
$profiler->queryEnd($q);
return $return;
}
@@ -67,7 +97,7 @@ class Db
*/
static public function query($sql, $parameters = array())
{
- return self::getDb()->query($sql, $parameters);
+ return self::get()->query($sql, $parameters);
}
/**
@@ -79,7 +109,7 @@ class Db
*/
static public function fetchAll($sql, $parameters = array())
{
- return self::getDb()->fetchAll($sql, $parameters);
+ return self::get()->fetchAll($sql, $parameters);
}
/**
@@ -91,7 +121,7 @@ class Db
*/
static public function fetchRow($sql, $parameters = array())
{
- return self::getDb()->fetchRow($sql, $parameters);
+ return self::get()->fetchRow($sql, $parameters);
}
/**
@@ -103,7 +133,7 @@ class Db
*/
static public function fetchOne($sql, $parameters = array())
{
- return self::getDb()->fetchOne($sql, $parameters);
+ return self::get()->fetchOne($sql, $parameters);
}
/**
@@ -115,7 +145,7 @@ class Db
*/
static public function fetchAssoc($sql, $parameters = array())
{
- return self::getDb()->fetchAssoc($sql, $parameters);
+ return self::get()->fetchAssoc($sql, $parameters);
}
/**
@@ -379,7 +409,7 @@ class Db
*/
$sql = 'SELECT GET_LOCK(?, 1)';
- $db = \Zend_Registry::get('db');
+ $db = self::get();
while ($maxRetries > 0) {
if ($db->fetchOne($sql, array($lockName)) == '1') {
@@ -400,7 +430,7 @@ class Db
{
$sql = 'SELECT RELEASE_LOCK(?)';
- $db = \Zend_Registry::get('db');
+ $db = self::get();
return $db->fetchOne($sql, array($lockName)) == '1';
}
diff --git a/core/Db/BatchInsert.php b/core/Db/BatchInsert.php
index 78a05546c9..019cd4d51c 100644
--- a/core/Db/BatchInsert.php
+++ b/core/Db/BatchInsert.php
@@ -18,7 +18,6 @@ use Piwik\Db;
use Piwik\DbHelper;
use Piwik\Piwik;
use Piwik\SettingsServer;
-use Zend_Registry;
class BatchInsert
{
@@ -62,7 +61,7 @@ class BatchInsert
{
$filePath = PIWIK_USER_PATH . '/' . AssetManager::MERGED_FILE_DIR . $tableName . '-' . Common::generateUniqId() . '.csv';
- if (Zend_Registry::get('db')->hasBulkLoader()) {
+ if (Db::get()->hasBulkLoader()) {
try {
$fileSpec = array(
'delim' => "\t",
@@ -185,7 +184,7 @@ class BatchInsert
// echo $sql . ' ---- ' . $e->getMessage();
$code = $e->getCode();
$message = $e->getMessage() . ($code ? "[$code]" : '');
- if (!Zend_Registry::get('db')->isErrNo($e, '1148')) {
+ if (!Db::get()->isErrNo($e, '1148')) {
Piwik::log(sprintf("LOAD DATA INFILE failed... Error was: %s", $message));
}
$exceptions[] = "\n Try #" . (count($exceptions) + 1) . ': ' . $queryStart . ": " . $message;
diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Myisam.php
index 5f0a81c92f..58430ff071 100644
--- a/core/Db/Schema/Myisam.php
+++ b/core/Db/Schema/Myisam.php
@@ -17,7 +17,6 @@ use Piwik\Date;
use Piwik\Db\SchemaInterface;
use Piwik\Db;
use Piwik\DbHelper;
-use Zend_Registry;
/**
* MySQL schema
@@ -35,7 +34,7 @@ class Myisam implements SchemaInterface
*/
static private function hasStorageEngine($engineName)
{
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$allEngines = $db->fetchAssoc('SHOW ENGINES');
if (array_key_exists($engineName, $allEngines)) {
$support = $allEngines[$engineName]['Support'];
@@ -453,7 +452,7 @@ class Myisam implements SchemaInterface
if (is_null($this->tablesInstalled)
|| $forceReload === true
) {
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$config = Config::getInstance();
$prefixTables = $config->database['tables_prefix'];
@@ -516,7 +515,7 @@ class Myisam implements SchemaInterface
*/
public function createTables()
{
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$config = Config::getInstance();
$prefixTables = $config->database['tables_prefix'];
@@ -540,7 +539,7 @@ class Myisam implements SchemaInterface
{
// The anonymous user is the user that is assigned by default
// note that the token_auth value is anonymous, which is assigned by default as well in the Login plugin
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$db->query("INSERT INTO " . Common::prefixTable("user") . "
VALUES ( 'anonymous', '', 'anonymous', 'anonymous@example.org', 'anonymous', '" . Date::factory('now')->getDatetime() . "' );");
}
@@ -564,7 +563,7 @@ class Myisam implements SchemaInterface
public function dropTables($doNotDelete = array())
{
$tablesAlreadyInstalled = $this->getTablesInstalled();
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$doNotDeletePattern = '/(' . implode('|', $doNotDelete) . ')/';
diff --git a/core/DbHelper.php b/core/DbHelper.php
index 67f4560192..91c6065e2b 100644
--- a/core/DbHelper.php
+++ b/core/DbHelper.php
@@ -94,7 +94,7 @@ class DbHelper
*/
public static function isDatabaseConnectionUTF8()
{
- return \Zend_Registry::get('db')->isConnectionUTF8();
+ return Db::get()->isConnectionUTF8();
}
/**
@@ -107,7 +107,7 @@ class DbHelper
*/
public static function checkDatabaseVersion()
{
- \Zend_Registry::get('db')->checkServerVersion();
+ Db::get()->checkServerVersion();
}
/**
@@ -115,32 +115,7 @@ class DbHelper
*/
public static function disconnectDatabase()
{
- \Zend_Registry::get('db')->closeConnection();
- }
-
- /**
- * Create database object and connect to database
- * @param array|null $dbInfos
- */
- public static function createDatabaseObject($dbInfos = null)
- {
- $config = Config::getInstance();
-
- if (is_null($dbInfos)) {
- $dbInfos = $config->database;
- }
-
- Piwik_PostEvent('Reporting.getDatabaseConfig', array(&$dbInfos));
-
- $dbInfos['profiler'] = $config->Debug['enable_sql_profiler'];
-
- $db = null;
- Piwik_PostEvent('Reporting.createDatabase', array(&$db));
- if (is_null($db)) {
- $adapter = $dbInfos['adapter'];
- $db = @Adapter::factory($adapter, $dbInfos);
- }
- \Zend_Registry::set('db', $db);
+ Db::get()->closeConnection();
}
/**
diff --git a/core/FrontController.php b/core/FrontController.php
index c98c5e5005..89aaefd9ef 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -259,7 +259,7 @@ class FrontController
}
try {
- DbHelper::createDatabaseObject();
+ Db::createDatabaseObject();
} catch (Exception $e) {
if (self::shouldRethrowException()) {
throw $e;
diff --git a/core/Log.php b/core/Log.php
index a2720098dd..bb2b624ee3 100644
--- a/core/Log.php
+++ b/core/Log.php
@@ -76,7 +76,7 @@ abstract class Log extends \Zend_Log
function addWriteToDatabase()
{
$writerDb = new \Zend_Log_Writer_Db(
- \Zend_Registry::get('db'),
+ Db::get(),
$this->logToDatabaseTableName,
$this->logToDatabaseColumnMapping);
diff --git a/core/Profiler.php b/core/Profiler.php
index 76acd914e7..b959e3990c 100644
--- a/core/Profiler.php
+++ b/core/Profiler.php
@@ -50,7 +50,7 @@ class Profiler
*/
public static function displayDbProfileReport()
{
- $profiler = \Zend_Registry::get('db')->getProfiler();
+ $profiler = Db::get()->getProfiler();
if (!$profiler->getEnabled()) {
throw new \Exception("To display the profiler you should enable enable_sql_profiler on your config/config.ini.php file");
@@ -144,7 +144,7 @@ class Profiler
*/
public static function getDbElapsedSecs()
{
- $profiler = \Zend_Registry::get('db')->getProfiler();
+ $profiler = Db::get()->getProfiler();
return $profiler->getTotalElapsedSecs();
}
@@ -155,7 +155,7 @@ class Profiler
*/
public static function getQueryCount()
{
- $profiler = \Zend_Registry::get('db')->getProfiler();
+ $profiler = Db::get()->getProfiler();
return $profiler->getTotalNumQueries();
}
diff --git a/core/Session.php b/core/Session.php
index 6cf0ee21a8..221c62bac2 100644
--- a/core/Session.php
+++ b/core/Session.php
@@ -12,7 +12,6 @@ namespace Piwik;
use Exception;
use Piwik\Session\SaveHandler\DbTable;
-use Zend_Registry;
use Zend_Session;
/**
@@ -95,7 +94,7 @@ class Session extends Zend_Session
// - user - we can't verify that user-defined session handler functions have already been set via session_set_save_handler()
// - mm - this handler is not recommended, unsupported, not available for Windows, and has a potential concurrency issue
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$config = array(
'name' => Common::prefixTable('session'),
diff --git a/core/Tracker.php b/core/Tracker.php
index e4c819ae55..ad1f40e736 100644
--- a/core/Tracker.php
+++ b/core/Tracker.php
@@ -398,9 +398,9 @@ class Tracker
$config = Config::getInstance();
try {
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
} catch (Exception $e) {
- DbHelper::createDatabaseObject();
+ Db::createDatabaseObject();
}
$pluginsManager = PluginsManager::getInstance();
diff --git a/core/Updater.php b/core/Updater.php
index 9fef7ff41f..0783b964f3 100644
--- a/core/Updater.php
+++ b/core/Updater.php
@@ -249,7 +249,7 @@ class Updater
$currentVersion = Piwik_GetOption('version_' . $name);
} catch (\Exception $e) {
// mysql error 1146: table doesn't exist
- if (\Zend_Registry::get('db')->isErrNo($e, '1146')) {
+ if (Db::get()->isErrNo($e, '1146')) {
// case when the option table is not yet created (before 0.2.10)
$currentVersion = false;
} else {
@@ -294,7 +294,7 @@ class Updater
Db::exec($update);
} catch (\Exception $e) {
if (($ignoreError === false)
- || !\Zend_Registry::get('db')->isErrNo($e, $ignoreError)
+ || !Db::get()->isErrNo($e, $ignoreError)
) {
$message = $file . ":\nError trying to execute the query '" . $update . "'.\nThe error was: " . $e->getMessage();
throw new Updater_UpdateErrorException($message);
diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php
index 4de67194d8..58bdc303c9 100644
--- a/plugins/Dashboard/Dashboard.php
+++ b/plugins/Dashboard/Dashboard.php
@@ -16,7 +16,6 @@ use Piwik\Common;
use Piwik\Site;
use Piwik\Db;
use Piwik\WidgetsList;
-use Zend_Registry;
/**
* @package Dashboard
@@ -264,7 +263,7 @@ class Dashboard extends \Piwik\Plugin
} catch (Exception $e) {
// mysql code error 1050:table already exists
// see bug #153 http://dev.piwik.org/trac/ticket/153
- if (!Zend_Registry::get('db')->isErrNo($e, '1050')) {
+ if (!Db::get()->isErrNo($e, '1050')) {
throw $e;
}
}
diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php
index 6f298348e9..bdff5eadcc 100644
--- a/plugins/DevicesDetection/DevicesDetection.php
+++ b/plugins/DevicesDetection/DevicesDetection.php
@@ -19,7 +19,6 @@ use Piwik\Plugins\DevicesDetection\Archiver;
use Piwik\WidgetsList;
use Piwik\Db;
use UserAgentParserEnhanced;
-use Zend_Registry;
require_once PIWIK_INCLUDE_PATH . "/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php";
require_once PIWIK_INCLUDE_PATH . '/plugins/DevicesDetection/functions.php';
@@ -224,7 +223,7 @@ class DevicesDetection extends \Piwik\Plugin
Db::exec($q2);
}
} catch (Exception $e) {
- if (!Zend_Registry::get('db')->isErrNo($e, '1060')) {
+ if (!Db::get()->isErrNo($e, '1060')) {
throw $e;
}
}
diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php
index c80ade9ac3..59866c8923 100644
--- a/plugins/Goals/API.php
+++ b/plugins/Goals/API.php
@@ -111,7 +111,7 @@ class API
$pattern = $this->checkPattern($pattern);
// save in db
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$idGoal = $db->fetchOne("SELECT max(idgoal) + 1
FROM " . Common::prefixTable('goal') . "
WHERE idsite = ?", $idSite);
@@ -157,7 +157,7 @@ class API
$name = $this->checkName($name);
$pattern = $this->checkPattern($pattern);
$this->checkPatternIsValid($patternType, $pattern);
- \Zend_Registry::get('db')->update(Common::prefixTable('goal'),
+ Db::get()->update(Common::prefixTable('goal'),
array(
'name' => $name,
'match_attribute' => $matchAttribute,
diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php
index e6528ed6f8..234467f0e0 100644
--- a/plugins/Installation/Controller.php
+++ b/plugins/Installation/Controller.php
@@ -234,7 +234,7 @@ class Controller extends \Piwik\Controller\Admin
}
$this->createDbFromSessionInformation();
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
try {
$db->checkClientVersion();
@@ -543,7 +543,7 @@ class Controller extends \Piwik\Controller\Admin
{
$dbInfos = $this->session->db_infos;
Config::getInstance()->database = $dbInfos;
- DbHelper::createDatabaseObject($dbInfos);
+ Db::createDatabaseObject($dbInfos);
}
/**
diff --git a/plugins/Installation/FormDatabaseSetup.php b/plugins/Installation/FormDatabaseSetup.php
index b4b8550f03..9e4a128719 100644
--- a/plugins/Installation/FormDatabaseSetup.php
+++ b/plugins/Installation/FormDatabaseSetup.php
@@ -16,6 +16,7 @@ use HTML_QuickForm2_Factory;
use HTML_QuickForm2_Rule;
use Piwik\Db\Adapter;
use Piwik\DbHelper;
+use Piwik\Db;
use Piwik\Filesystem;
use Piwik\QuickForm2;
use Zend_Db_Adapter_Exception;
@@ -120,7 +121,7 @@ class FormDatabaseSetup extends QuickForm2
}
try {
- @DbHelper::createDatabaseObject($dbInfos);
+ @Db::createDatabaseObject($dbInfos);
} catch (Zend_Db_Adapter_Exception $e) {
$db = Adapter::factory($adapter, $dbInfos, $connect = false);
@@ -128,11 +129,11 @@ class FormDatabaseSetup extends QuickForm2
if ($db->isErrNo($e, '1049')) {
$dbInfosConnectOnly = $dbInfos;
$dbInfosConnectOnly['dbname'] = null;
- @DbHelper::createDatabaseObject($dbInfosConnectOnly);
+ @Db::createDatabaseObject($dbInfosConnectOnly);
@DbHelper::createDatabase($dbInfos['dbname']);
// select the newly created database
- @DbHelper::createDatabaseObject($dbInfos);
+ @Db::createDatabaseObject($dbInfos);
} else {
throw $e;
}
@@ -179,7 +180,7 @@ class Rule_checkUserPrivileges extends HTML_QuickForm2_Rule
}
}
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
try {
// try to drop tables before running privilege tests
diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php
index 4372676c74..5d962d9476 100644
--- a/plugins/LanguagesManager/LanguagesManager.php
+++ b/plugins/LanguagesManager/LanguagesManager.php
@@ -20,7 +20,6 @@ use Piwik\Plugins\LanguagesManager\API;
use Piwik\View;
use Piwik\Db;
use Piwik\Translate;
-use Zend_Registry;
/**
*
@@ -116,7 +115,7 @@ class LanguagesManager extends \Piwik\Plugin
} catch (Exception $e) {
// mysql code error 1050:table already exists
// see bug #153 http://dev.piwik.org/trac/ticket/153
- if (!Zend_Registry::get('db')->isErrNo($e, '1050')) {
+ if (!Db::get()->isErrNo($e, '1050')) {
throw $e;
}
}
diff --git a/plugins/PDFReports/API.php b/plugins/PDFReports/API.php
index 909c61ce07..df72e8c39c 100644
--- a/plugins/PDFReports/API.php
+++ b/plugins/PDFReports/API.php
@@ -110,7 +110,7 @@ class API
// validation of requested reports
$reports = self::validateRequestedReports($idSite, $reportType, $reports);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$idReport = $db->fetchOne("SELECT max(idreport) + 1 FROM " . Common::prefixTable('report'));
if ($idReport == false) {
@@ -170,7 +170,7 @@ class API
// validation of requested reports
$reports = self::validateRequestedReports($idSite, $reportType, $reports);
- \Zend_Registry::get('db')->update(Common::prefixTable('report'),
+ Db::get()->update(Common::prefixTable('report'),
array(
'description' => $description,
'idsegment' => $idSegment,
@@ -198,7 +198,7 @@ class API
$report = reset($pdfReports);
Piwik::checkUserIsSuperUserOrTheUser($report['login']);
- \Zend_Registry::get('db')->update(Common::prefixTable('report'),
+ Db::get()->update(Common::prefixTable('report'),
array(
'deleted' => 1,
),
@@ -548,7 +548,7 @@ class API
);
// Update flag in DB
- \Zend_Registry::get('db')->update(Common::prefixTable('report'),
+ Db::get()->update(Common::prefixTable('report'),
array('ts_last_sent' => Date::now()->getDatetime()),
"idreport = " . $report['idreport']
);
diff --git a/plugins/PDFReports/PDFReports.php b/plugins/PDFReports/PDFReports.php
index 9fe7f8c54a..295adbab79 100644
--- a/plugins/PDFReports/PDFReports.php
+++ b/plugins/PDFReports/PDFReports.php
@@ -27,7 +27,6 @@ use Piwik\ScheduledTime;
use Piwik\Site;
use Piwik\View;
use Zend_Mime;
-use Zend_Registry;
/**
*
@@ -550,7 +549,7 @@ class PDFReports extends \Piwik\Plugin
Db::exec($query);
}
} catch (Exception $e) {
- if (!Zend_Registry::get('db')->isErrNo($e, '1050')) {
+ if (!Db::get()->isErrNo($e, '1050')) {
throw $e;
}
}
diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php
index f2562e9485..b6013e0e3c 100644
--- a/plugins/Provider/Provider.php
+++ b/plugins/Provider/Provider.php
@@ -18,7 +18,6 @@ use Piwik\ArchiveProcessor;
use Piwik\Db;
use Piwik\Plugins\Provider\Archiver;
use Piwik\WidgetsList;
-use Zend_Registry;
/**
*
@@ -78,7 +77,7 @@ class Provider extends \Piwik\Plugin
try {
Db::exec($query);
} catch (Exception $e) {
- if (!Zend_Registry::get('db')->isErrNo($e, '1060')) {
+ if (!Db::get()->isErrNo($e, '1060')) {
throw $e;
}
}
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php
index 1dbc8b0811..7c96fc25b6 100644
--- a/plugins/SegmentEditor/API.php
+++ b/plugins/SegmentEditor/API.php
@@ -15,6 +15,7 @@ use Piwik\Piwik;
use Piwik\Common;
use Piwik\Date;
use Piwik\Segment;
+use Piwik\Db;
/**
* The SegmentEditor API lets you add, update, delete custom Segments, and list saved segments.a
@@ -138,7 +139,7 @@ class API
Piwik_PostEvent(self::DELETE_SEGMENT_EVENT, array(&$idSegment));
$segment = $this->getSegmentOrFail($idSegment);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$db->delete(Common::prefixTable('segment'), 'idsegment = ' . $idSegment);
return true;
}
@@ -175,7 +176,7 @@ class API
'ts_last_edit' => Date::now()->getDatetime(),
);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$db->update(Common::prefixTable("segment"),
$bind,
"idsegment = $idSegment"
@@ -203,7 +204,7 @@ class API
$enabledAllUsers = $this->checkEnabledAllUsers($enabledAllUsers);
$autoArchive = $this->checkAutoArchive($autoArchive, $idSite);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$bind = array(
'name' => $name,
'definition' => $definition,
@@ -231,7 +232,7 @@ class API
if (!is_numeric($idSegment)) {
throw new Exception("idSegment should be numeric.");
}
- $segment = \Zend_Registry::get('db')->fetchRow("SELECT * " .
+ $segment = Db::get()->fetchRow("SELECT * " .
" FROM " . Common::prefixTable("segment") .
" WHERE idsegment = ?", $idSegment);
@@ -289,7 +290,7 @@ class API
AND deleted = 0
$extraWhere
ORDER BY name ASC";
- $segments = \Zend_Registry::get('db')->fetchAll($sql, $bind);
+ $segments = Db::get()->fetchAll($sql, $bind);
return $segments;
}
diff --git a/plugins/SegmentEditor/SegmentEditor.php b/plugins/SegmentEditor/SegmentEditor.php
index 8037d868e9..2fdaea66ed 100644
--- a/plugins/SegmentEditor/SegmentEditor.php
+++ b/plugins/SegmentEditor/SegmentEditor.php
@@ -16,7 +16,6 @@ use Piwik\Plugins\SegmentEditor\API;
use Piwik\Plugins\SegmentEditor\Controller;
use Piwik\Version;
use Piwik\Db;
-use Zend_Registry;
/**
* @package SegmentEditor
@@ -94,7 +93,7 @@ class SegmentEditor extends \Piwik\Plugin
Db::exec($query);
}
} catch (Exception $e) {
- if (!Zend_Registry::get('db')->isErrNo($e, '1050')) {
+ if (!Db::get()->isErrNo($e, '1050')) {
throw $e;
}
}
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php
index 9231b3855a..6b299349d7 100644
--- a/plugins/SitesManager/API.php
+++ b/plugins/SitesManager/API.php
@@ -99,9 +99,9 @@ class API
Piwik::checkUserIsSuperUser();
$group = trim($group);
- $sites = \Zend_Registry::get('db')->fetchAll("SELECT *
- FROM " . Common::prefixTable("site") . "
- WHERE `group` = ?", $group);
+ $sites = Db::get()->fetchAll("SELECT *
+ FROM " . Common::prefixTable("site") . "
+ WHERE `group` = ?", $group);
return $sites;
}
@@ -114,7 +114,7 @@ class API
public function getSitesGroups()
{
Piwik::checkUserIsSuperUser();
- $groups = \Zend_Registry::get('db')->fetchAll("SELECT DISTINCT `group` FROM " . Common::prefixTable("site"));
+ $groups = Db::get()->fetchAll("SELECT DISTINCT `group` FROM " . Common::prefixTable("site"));
$cleanedGroups = array();
foreach ($groups as $group) {
$cleanedGroups[] = $group['group'];
@@ -133,9 +133,9 @@ class API
public function getSiteFromId($idSite)
{
Piwik::checkUserHasViewAccess($idSite);
- $site = \Zend_Registry::get('db')->fetchRow("SELECT *
- FROM " . Common::prefixTable("site") . "
- WHERE idsite = ?", $idSite);
+ $site = Db::get()->fetchRow("SELECT *
+ FROM " . Common::prefixTable("site") . "
+ WHERE idsite = ?", $idSite);
return $site;
}
@@ -148,7 +148,7 @@ class API
*/
private function getAliasSiteUrlsFromId($idSite)
{
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$result = $db->fetchAll("SELECT url
FROM " . Common::prefixTable("site_url") . "
WHERE idsite = ?", $idSite);
@@ -198,7 +198,7 @@ class API
public function getAllSites()
{
Piwik::checkUserIsSuperUser();
- $sites = \Zend_Registry::get('db')->fetchAll("SELECT * FROM " . Common::prefixTable("site") . " ORDER BY idsite ASC");
+ $sites = Db::get()->fetchAll("SELECT * FROM " . Common::prefixTable("site") . " ORDER BY idsite ASC");
$return = array();
foreach ($sites as $site) {
$return[$site['idsite']] = $site;
@@ -363,7 +363,7 @@ class API
$limit = "LIMIT " . (int)$limit;
}
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$sites = $db->fetchAll("SELECT *
FROM " . Common::prefixTable("site") . "
WHERE idsite IN (" . implode(", ", $idSites) . ")
@@ -392,7 +392,7 @@ class API
$url = $this->removeTrailingSlash($url);
list($url, $urlBis) = $this->getNormalizedUrls($url);
if (Piwik::isUserIsSuperUser()) {
- $ids = \Zend_Registry::get('db')->fetchAll(
+ $ids = Db::get()->fetchAll(
'SELECT idsite
FROM ' . Common::prefixTable('site') . '
WHERE (main_url = ? OR main_url = ?) ' .
@@ -402,7 +402,7 @@ class API
WHERE (url = ? OR url = ?) ', array($url, $urlBis, $url, $urlBis));
} else {
$login = Piwik::getCurrentUserLogin();
- $ids = \Zend_Registry::get('db')->fetchAll(
+ $ids = Db::get()->fetchAll(
'SELECT idsite
FROM ' . Common::prefixTable('site') . '
WHERE (main_url = ? OR main_url = ?)' .
@@ -430,7 +430,7 @@ class API
Piwik::checkUserIsSuperUser();
$timezones = Piwik::getArrayFromApiParameter($timezones);
$timezones = array_unique($timezones);
- $ids = \Zend_Registry::get('db')->fetchAll(
+ $ids = Db::get()->fetchAll(
'SELECT idsite
FROM ' . Common::prefixTable('site') . '
WHERE timezone IN (' . Common::getSqlStringFieldsArray($timezones) . ')
@@ -507,7 +507,7 @@ class API
}
$this->checkValidCurrency($currency);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$url = $urls[0];
$urls = array_slice($urls, 1);
@@ -581,7 +581,7 @@ class API
throw new Exception(Piwik_TranslateException("SitesManager_ExceptionDeleteSite"));
}
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$db->query("DELETE FROM " . Common::prefixTable("site") . "
WHERE idsite = ?", $idSite);
@@ -1045,7 +1045,7 @@ class API
$bind['sitesearch_category_parameters'] = $searchCategoryParameters;
$bind['name'] = $siteName;
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$db->update(Common::prefixTable("site"),
$bind,
"idsite = $idSite"
@@ -1189,7 +1189,7 @@ class API
private function insertSiteUrls($idSite, $urls)
{
if (count($urls) != 0) {
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
foreach ($urls as $url) {
$db->insert(Common::prefixTable("site_url"), array(
'idsite' => $idSite,
@@ -1205,7 +1205,7 @@ class API
*/
private function deleteSiteAliasUrls($idsite)
{
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$db->query("DELETE FROM " . Common::prefixTable("site_url") . "
WHERE idsite = ?", $idsite);
}
@@ -1341,7 +1341,7 @@ class API
}
$ids_str .= $id_val;
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$bind = array('%' . $pattern . '%', 'http%' . $pattern . '%');
// Also match the idsite
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php
index 64a2e8f5f9..57d69fc962 100644
--- a/plugins/UsersManager/API.php
+++ b/plugins/UsersManager/API.php
@@ -132,7 +132,7 @@ class API
$where = 'WHERE login IN (' . Common::getSqlStringFieldsArray($userLogins) . ')';
$bind = $userLogins;
}
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$users = $db->fetchAll("SELECT *
FROM " . Common::prefixTable("user") . "
$where
@@ -155,7 +155,7 @@ class API
{
Piwik::checkUserHasSomeAdminAccess();
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$users = $db->fetchAll("SELECT login
FROM " . Common::prefixTable("user") . "
ORDER BY login ASC");
@@ -187,7 +187,7 @@ class API
$this->checkAccessType($access);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$users = $db->fetchAll("SELECT login,idsite
FROM " . Common::prefixTable("access")
. " WHERE access = ?
@@ -218,7 +218,7 @@ class API
{
Piwik::checkUserHasAdminAccess($idSite);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$users = $db->fetchAll("SELECT login,access
FROM " . Common::prefixTable("access")
. " WHERE idsite = ?", $idSite);
@@ -234,7 +234,7 @@ class API
Piwik::checkUserHasAdminAccess($idSite);
$this->checkAccessType($access);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$users = $db->fetchAll("SELECT login
FROM " . Common::prefixTable("access")
. " WHERE idsite = ? AND access = ?", array($idSite, $access));
@@ -271,7 +271,7 @@ class API
$this->checkUserExists($userLogin);
$this->checkUserIsNotSuperUser($userLogin);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$users = $db->fetchAll("SELECT idsite,access
FROM " . Common::prefixTable("access")
. " WHERE login = ?", $userLogin);
@@ -298,7 +298,7 @@ class API
$this->checkUserExists($userLogin);
$this->checkUserIsNotSuperUser($userLogin);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$user = $db->fetchRow("SELECT *
FROM " . Common::prefixTable("user")
. " WHERE login = ?", $userLogin);
@@ -317,7 +317,7 @@ class API
Piwik::checkUserIsSuperUser();
$this->checkUserEmailExists($userEmail);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$user = $db->fetchRow("SELECT *
FROM " . Common::prefixTable("user")
. " WHERE email = ?", $userEmail);
@@ -383,7 +383,7 @@ class API
$token_auth = $this->getTokenAuth($userLogin, $passwordTransformed);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$db->insert(Common::prefixTable("user"), array(
'login' => $userLogin,
@@ -443,7 +443,7 @@ class API
$alias = $this->getCleanAlias($alias, $userLogin);
$token_auth = $this->getTokenAuth($userLogin, $password);
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$db->update(Common::prefixTable("user"),
array(
@@ -559,7 +559,7 @@ class API
$this->deleteUserAccess($userLogin, $idSites);
// delete UserAccess
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
// if the access is noaccess then we don't save it as this is the default value
// when no access are specified
@@ -639,7 +639,7 @@ class API
*/
private function deleteUserOnly($userLogin)
{
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
$db->query("DELETE FROM " . Common::prefixTable("user") . " WHERE login = ?", $userLogin);
Piwik_PostEvent('UsersManager.deleteUser', array($userLogin));
@@ -656,7 +656,7 @@ class API
*/
private function deleteUserAccess($userLogin, $idSites = null)
{
- $db = \Zend_Registry::get('db');
+ $db = Db::get();
if (is_null($idSites)) {
$db->query("DELETE FROM " . Common::prefixTable("access") .
diff --git a/tests/PHPUnit/DatabaseTestCase.php b/tests/PHPUnit/DatabaseTestCase.php
index 367ad570a1..112219f177 100644
--- a/tests/PHPUnit/DatabaseTestCase.php
+++ b/tests/PHPUnit/DatabaseTestCase.php
@@ -9,6 +9,7 @@ use Piwik\Config;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\DataTable\Manager;
use Piwik\DbHelper;
+use Piwik\Db;
use Piwik\Option;
use Piwik\Plugins\PDFReports\API;
use Piwik\Site;
@@ -38,13 +39,13 @@ class DatabaseTestCase extends PHPUnit_Framework_TestCase
$dbName = $dbConfig['dbname'];
$dbConfig['dbname'] = null;
- DbHelper::createDatabaseObject($dbConfig);
+ Db::createDatabaseObject($dbConfig);
DbHelper::dropDatabase();
DbHelper::createDatabase($dbName);
DbHelper::disconnectDatabase();
- DbHelper::createDatabaseObject();
+ Db::createDatabaseObject();
DbHelper::createTables();
\Piwik\Log::make();
diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php
index b0454d6438..c16614073c 100755
--- a/tests/PHPUnit/IntegrationTestCase.php
+++ b/tests/PHPUnit/IntegrationTestCase.php
@@ -69,7 +69,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
$oldDbName = $dbConfig['dbname'];
$dbConfig['dbname'] = null;
- DbHelper::createDatabaseObject($dbConfig);
+ Db::createDatabaseObject($dbConfig);
$dbConfig['dbname'] = $oldDbName;
}
@@ -165,7 +165,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
// reconnect once we're sure the database exists
Config::getInstance()->database['dbname'] = $dbName;
- DbHelper::createDatabaseObject();
+ Db::createDatabaseObject();
DbHelper::createTables();
\Piwik\Log::make();