diff options
-rw-r--r-- | core/DataAccess/ArchiveTableCreator.php | 5 | ||||
-rw-r--r-- | core/Db/BatchInsert.php | 3 | ||||
-rw-r--r-- | core/Db/Schema/Myisam.php | 9 | ||||
-rw-r--r-- | core/FrontController.php | 2 | ||||
-rw-r--r-- | core/Piwik.php | 121 | ||||
-rw-r--r-- | core/Tracker.php | 2 | ||||
-rw-r--r-- | index.php | 1 | ||||
-rw-r--r-- | plugins/Installation/Controller.php | 9 | ||||
-rw-r--r-- | plugins/Installation/FormDatabaseSetup.php | 10 | ||||
m--------- | plugins/SecurityInfo | 0 | ||||
-rw-r--r-- | tests/PHPUnit/DatabaseTestCase.php | 16 | ||||
-rwxr-xr-x | tests/PHPUnit/IntegrationTestCase.php | 17 | ||||
-rw-r--r-- | tests/PHPUnit/UITest.php | 8 | ||||
-rw-r--r-- | tests/PHPUnit/bootstrap.php | 2 |
14 files changed, 45 insertions, 160 deletions
diff --git a/core/DataAccess/ArchiveTableCreator.php b/core/DataAccess/ArchiveTableCreator.php index 8e135f996f..aa7fdf5c4e 100644 --- a/core/DataAccess/ArchiveTableCreator.php +++ b/core/DataAccess/ArchiveTableCreator.php @@ -12,9 +12,10 @@ namespace Piwik\DataAccess; use Exception; -use Piwik\Piwik; use Piwik\Common; use Piwik\Date; +use Piwik\DbHelper; +use Piwik\Piwik; use Zend_Registry; class ArchiveTableCreator @@ -52,7 +53,7 @@ class ArchiveTableCreator if (!in_array($tableName, self::$tablesAlreadyInstalled)) { $db = \Zend_Registry::get('db'); - $sql = Piwik::getTableCreateSql($tableNamePrefix); + $sql = DbHelper::getTableCreateSql($tableNamePrefix); // replace table name template by real name $tableNamePrefix = Common::prefixTable($tableNamePrefix); diff --git a/core/Db/BatchInsert.php b/core/Db/BatchInsert.php index d0b3624893..78a05546c9 100644 --- a/core/Db/BatchInsert.php +++ b/core/Db/BatchInsert.php @@ -15,6 +15,7 @@ use Piwik\AssetManager; use Piwik\Common; use Piwik\Config; use Piwik\Db; +use Piwik\DbHelper; use Piwik\Piwik; use Piwik\SettingsServer; use Zend_Registry; @@ -75,7 +76,7 @@ class BatchInsert ); // hack for charset mismatch - if (!Piwik::isDatabaseConnectionUTF8() && !isset(Config::getInstance()->database['charset'])) { + if (!DbHelper::isDatabaseConnectionUTF8() && !isset(Config::getInstance()->database['charset'])) { $fileSpec['charset'] = 'latin1'; } diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Myisam.php index 9502a74f28..5f0a81c92f 100644 --- a/core/Db/Schema/Myisam.php +++ b/core/Db/Schema/Myisam.php @@ -11,15 +11,14 @@ namespace Piwik\Db\Schema; use Exception; -use Piwik\Config; -use Piwik\Db\SchemaInterface; -use Piwik\Piwik; use Piwik\Common; +use Piwik\Config; use Piwik\Date; +use Piwik\Db\SchemaInterface; use Piwik\Db; +use Piwik\DbHelper; use Zend_Registry; - /** * MySQL schema * @@ -414,7 +413,7 @@ class Myisam implements SchemaInterface */ public function getTableCreateSql($tableName) { - $tables = Piwik::getTablesCreateSql(); + $tables = DbHelper::getTablesCreateSql(); if (!isset($tables[$tableName])) { throw new Exception("The table '$tableName' SQL creation code couldn't be found."); diff --git a/core/FrontController.php b/core/FrontController.php index 0d30d38098..7a3660ee34 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -260,7 +260,7 @@ class FrontController } try { - Piwik::createDatabaseObject(); + DbHelper::createDatabaseObject(); } catch (Exception $e) { if (self::shouldRethrowException()) { throw $e; diff --git a/core/Piwik.php b/core/Piwik.php index 08bc16d02b..5473d6faa9 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -554,70 +554,6 @@ class Piwik } /* - * Global database object - */ - - /** - * Create database object and connect to database - * @param array|null $dbInfos - */ - static public 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); - } - - /** - * Disconnect from database - */ - static public function disconnectDatabase() - { - \Zend_Registry::get('db')->closeConnection(); - } - - /** - * Checks the database server version against the required minimum - * version. - * - * @see config/global.ini.php - * @since 0.4.4 - * @throws Exception if server version is less than the required version - */ - static public function checkDatabaseVersion() - { - \Zend_Registry::get('db')->checkServerVersion(); - } - - /** - * Check database connection character set is utf8. - * - * @return bool True if it is (or doesn't matter); false otherwise - */ - static public function isDatabaseConnectionUTF8() - { - return \Zend_Registry::get('db')->isConnectionUTF8(); - } - - /* - * Global log object - */ - - /* * User input validation */ @@ -663,63 +599,6 @@ class Piwik */ /** - * Is the schema available? - * - * @return bool True if schema is available; false otherwise - */ - static public function isAvailable() - { - return Schema::getInstance()->isAvailable(); - } - - /** - * Get the SQL to create a specific Piwik table - * - * @param string $tableName - * @return string SQL - */ - static public function getTableCreateSql($tableName) - { - return Schema::getInstance()->getTableCreateSql($tableName); - } - - /** - * Get the SQL to create Piwik tables - * - * @return array array of strings containing SQL - */ - static public function getTablesCreateSql() - { - return Schema::getInstance()->getTablesCreateSql(); - } - - /** - * Create database - * - * @param string|null $dbName - */ - static public function createDatabase($dbName = null) - { - Schema::getInstance()->createDatabase($dbName); - } - - /** - * Drop database - */ - static public function dropDatabase() - { - Schema::getInstance()->dropDatabase(); - } - - /** - * Create all tables - */ - static public function createTables() - { - Schema::getInstance()->createTables(); - } - - /** * Creates an entry in the User table for the "anonymous" user. */ static public function createAnonymousUser() diff --git a/core/Tracker.php b/core/Tracker.php index 1805ac5bd0..ac3a14e14f 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -370,7 +370,7 @@ class Tracker try { $db = \Zend_Registry::get('db'); } catch (Exception $e) { - Piwik::createDatabaseObject(); + DbHelper::createDatabaseObject(); } $pluginsManager = PluginsManager::getInstance(); @@ -50,3 +50,4 @@ if (!defined('PIWIK_ENABLE_DISPATCH') || PIWIK_ENABLE_DISPATCH) { $controller->init(); $controller->dispatch(); } +\Piwik\DbHelper::dropDatabase();
\ No newline at end of file diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php index 23542bce63..981fa54bc7 100644 --- a/plugins/Installation/Controller.php +++ b/plugins/Installation/Controller.php @@ -18,6 +18,7 @@ use Piwik\Config; use Piwik\DataAccess\ArchiveTableCreator; use Piwik\Db\Adapter; use Piwik\Db; +use Piwik\DbHelper; use Piwik\Filechecks; use Piwik\Filesystem; use Piwik\Http; @@ -185,7 +186,7 @@ class Controller extends \Piwik\Controller\Admin $dbInfos = $form->createDatabaseObject(); $this->session->databaseCreated = true; - Piwik::checkDatabaseVersion(); + DbHelper::checkDatabaseVersion(); $this->session->databaseVersionOk = true; $this->session->db_infos = $dbInfos; @@ -242,7 +243,7 @@ class Controller extends \Piwik\Controller\Admin $error = true; } - if (!Piwik::isDatabaseConnectionUTF8()) { + if (!DbHelper::isDatabaseConnectionUTF8()) { $dbInfos = $this->session->db_infos; $dbInfos['charset'] = 'utf8'; $this->session->db_infos = $dbInfos; @@ -311,7 +312,7 @@ class Controller extends \Piwik\Controller\Admin $this->session->skipThisStep = $tmp; } } else { - Piwik::createTables(); + DbHelper::createTables(); Piwik::createAnonymousUser(); $updater = new Updater(); @@ -543,7 +544,7 @@ class Controller extends \Piwik\Controller\Admin { $dbInfos = $this->session->db_infos; Config::getInstance()->database = $dbInfos; - Piwik::createDatabaseObject($dbInfos); + DbHelper::createDatabaseObject($dbInfos); } /** diff --git a/plugins/Installation/FormDatabaseSetup.php b/plugins/Installation/FormDatabaseSetup.php index ce0d58f11a..b4b8550f03 100644 --- a/plugins/Installation/FormDatabaseSetup.php +++ b/plugins/Installation/FormDatabaseSetup.php @@ -15,8 +15,8 @@ use HTML_QuickForm2_DataSource_Array; use HTML_QuickForm2_Factory; use HTML_QuickForm2_Rule; use Piwik\Db\Adapter; +use Piwik\DbHelper; use Piwik\Filesystem; -use Piwik\Piwik; use Piwik\QuickForm2; use Zend_Db_Adapter_Exception; @@ -120,7 +120,7 @@ class FormDatabaseSetup extends QuickForm2 } try { - @Piwik::createDatabaseObject($dbInfos); + @DbHelper::createDatabaseObject($dbInfos); } catch (Zend_Db_Adapter_Exception $e) { $db = Adapter::factory($adapter, $dbInfos, $connect = false); @@ -128,11 +128,11 @@ class FormDatabaseSetup extends QuickForm2 if ($db->isErrNo($e, '1049')) { $dbInfosConnectOnly = $dbInfos; $dbInfosConnectOnly['dbname'] = null; - @Piwik::createDatabaseObject($dbInfosConnectOnly); - @Piwik::createDatabase($dbInfos['dbname']); + @DbHelper::createDatabaseObject($dbInfosConnectOnly); + @DbHelper::createDatabase($dbInfos['dbname']); // select the newly created database - @Piwik::createDatabaseObject($dbInfos); + @DbHelper::createDatabaseObject($dbInfos); } else { throw $e; } diff --git a/plugins/SecurityInfo b/plugins/SecurityInfo deleted file mode 160000 -Subproject 7d4f2ea0d63886eda79087ef5884be12bf63b31 diff --git a/tests/PHPUnit/DatabaseTestCase.php b/tests/PHPUnit/DatabaseTestCase.php index 39395c375d..367ad570a1 100644 --- a/tests/PHPUnit/DatabaseTestCase.php +++ b/tests/PHPUnit/DatabaseTestCase.php @@ -8,7 +8,7 @@ use Piwik\Config; use Piwik\DataAccess\ArchiveTableCreator; use Piwik\DataTable\Manager; -use Piwik\Piwik; +use Piwik\DbHelper; use Piwik\Option; use Piwik\Plugins\PDFReports\API; use Piwik\Site; @@ -38,14 +38,14 @@ class DatabaseTestCase extends PHPUnit_Framework_TestCase $dbName = $dbConfig['dbname']; $dbConfig['dbname'] = null; - Piwik::createDatabaseObject($dbConfig); + DbHelper::createDatabaseObject($dbConfig); - Piwik::dropDatabase(); - Piwik::createDatabase($dbName); - Piwik::disconnectDatabase(); + DbHelper::dropDatabase(); + DbHelper::createDatabase($dbName); + DbHelper::disconnectDatabase(); - Piwik::createDatabaseObject(); - Piwik::createTables(); + DbHelper::createDatabaseObject(); + DbHelper::createTables(); \Piwik\Log::make(); // \Piwik\PluginsManager::getInstance()->loadPlugins(array()); @@ -69,7 +69,7 @@ class DatabaseTestCase extends PHPUnit_Framework_TestCase { parent::tearDown(); IntegrationTestCase::unloadAllPlugins(); - Piwik::dropDatabase(); + DbHelper::dropDatabase(); Manager::getInstance()->deleteAll(); Option::getInstance()->clearCache(); API::$cache = array(); diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index 0129e1c3e4..67fac0c6f8 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -15,6 +15,7 @@ use Piwik\Config; use Piwik\DataAccess\ArchiveTableCreator; use Piwik\DataTable\Manager; use Piwik\Db; +use Piwik\DbHelper; use Piwik\Option; use Piwik\Piwik; use Piwik\Plugins\LanguagesManager\API; @@ -68,7 +69,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase $oldDbName = $dbConfig['dbname']; $dbConfig['dbname'] = null; - Piwik::createDatabaseObject($dbConfig); + DbHelper::createDatabaseObject($dbConfig); $dbConfig['dbname'] = $oldDbName; } @@ -157,16 +158,16 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase self::connectWithoutDatabase(); if ($createEmptyDatabase) { - Piwik::dropDatabase(); + DbHelper::dropDatabase(); } - Piwik::createDatabase($dbName); - Piwik::disconnectDatabase(); + DbHelper::createDatabase($dbName); + DbHelper::disconnectDatabase(); // reconnect once we're sure the database exists Config::getInstance()->database['dbname'] = $dbName; - Piwik::createDatabaseObject(); + DbHelper::createDatabaseObject(); - Piwik::createTables(); + DbHelper::createTables(); \Piwik\Log::make(); \Piwik\PluginsManager::getInstance()->loadPlugins(array()); @@ -230,7 +231,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase } \Piwik\PluginsManager::getInstance()->unloadPlugins();*/ if ($dropDatabase) { - Piwik::dropDatabase(); + DbHelper::dropDatabase(); } Manager::getInstance()->deleteAll(); Option::getInstance()->clearCache(); @@ -1103,7 +1104,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase if (strpos($table, 'archive_') !== false && !in_array($table, $existingTables)) { $tableType = strpos($table, 'archive_numeric') !== false ? 'archive_numeric' : 'archive_blob'; - $createSql = Piwik::getTableCreateSql($tableType); + $createSql = DbHelper::getTableCreateSql($tableType); $createSql = str_replace(Common::prefixTable($tableType), $table, $createSql); Db::query($createSql); } diff --git a/tests/PHPUnit/UITest.php b/tests/PHPUnit/UITest.php index 4bc4aba9a9..a1aa74cdd8 100644 --- a/tests/PHPUnit/UITest.php +++ b/tests/PHPUnit/UITest.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -use Piwik\Date; -use Piwik\Piwik; use Piwik\Access; use Piwik\AssetManager; +use Piwik\Date; +use Piwik\DbHelper; use Piwik\Plugins\VisitsSummary\API; abstract class UITest extends IntegrationTestCase @@ -79,7 +79,7 @@ abstract class UITest extends IntegrationTestCase self::removeRecursiveLinks(); if (!Zend_Registry::get('db')) { - Piwik::createDatabaseObject(); + DbHelper::createDatabaseObject(); } parent::tearDownAfterClass(); @@ -90,7 +90,7 @@ abstract class UITest extends IntegrationTestCase parent::setUp(); if (!Zend_Registry::get('db')) { - Piwik::createDatabaseObject(); + DbHelper::createDatabaseObject(); } } diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php index 11749f00ce..9ad5a620f3 100644 --- a/tests/PHPUnit/bootstrap.php +++ b/tests/PHPUnit/bootstrap.php @@ -6,6 +6,8 @@ use Piwik\Http; +define('PIWIK_TEST_MODE', true); + if (!defined("PIWIK_PATH_TEST_TO_ROOT")) { define('PIWIK_PATH_TEST_TO_ROOT', realpath(dirname(__FILE__) . '/../..')); } |