diff --git a/config/global.ini.php b/config/global.ini.php index 69017538d9ec02f907fdbc8859c7c23959593f46..df84a0e3a466fb2e4ead7fb8fa9746e22a4ee679 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -19,6 +19,8 @@ dbname = tables_prefix = port = 3306 adapter = PDO_MYSQL +type = InnoDB + ; if charset is set to utf8, Piwik will ensure that it is storing its data using UTF8 charset. ; it will add a sql query SET at each page view. ; Piwik should work correctly without this setting. @@ -32,6 +34,7 @@ dbname = piwik_tests tables_prefix = piwiktests_ port = 3306 adapter = PDO_MYSQL +type = InnoDB [log] ; possible values for log: screen, database, file diff --git a/core/DataAccess/ArchiveTableCreator.php b/core/DataAccess/ArchiveTableCreator.php index 353606463197924a154788417bcca0abcd0a6898..6f8d0b90c62ff1051342317008ff2c8028e21d6b 100644 --- a/core/DataAccess/ArchiveTableCreator.php +++ b/core/DataAccess/ArchiveTableCreator.php @@ -49,7 +49,7 @@ class ArchiveTableCreator } if (!in_array($tableName, self::$tablesAlreadyInstalled)) { - $db = Db::get(); + $db = Db::get(); $sql = DbHelper::getTableCreateSql($tableNamePrefix); // replace table name template by real name diff --git a/core/Db.php b/core/Db.php index f982b59115b019bc861fa80d9c2d17a0cc061175..2e7c3c17f04f362f6d1684e89cc7d3ffa7d836c0 100644 --- a/core/Db.php +++ b/core/Db.php @@ -53,30 +53,22 @@ class Db return self::$connection; } - /** - * Connects to the database. - * - * Shouldn't be called directly, use {@link get()} instead. - * - * @param array|null $dbInfos Connection parameters in an array. Defaults to the `[database]` - * INI config section. - */ - public static function createDatabaseObject($dbInfos = null) + public static function getDbConfig($dbConfig = null) { $config = Config::getInstance(); - if (is_null($dbInfos)) { - $dbInfos = $config->database; + if (is_null($dbConfig)) { + $dbConfig = $config->database; } /** * Triggered before a database connection is established. - * + * * This event can be used to change the settings used to establish a connection. - * + * * @param array *$dbInfos Reference to an array containing database connection info, * including: - * + * * - **host**: The host name or IP address to the MySQL database. * - **username**: The username to use when connecting to the * database. @@ -85,13 +77,28 @@ class Db * - **dbname**: The name of the Piwik MySQL database. * - **port**: The MySQL database port to use. * - **adapter**: either `'PDO_MYSQL'` or `'MYSQLI'` + * - **type**: The MySQL engine to use, for instance 'InnoDB' */ - Piwik::postEvent('Reporting.getDatabaseConfig', array(&$dbInfos)); + Piwik::postEvent('Reporting.getDatabaseConfig', array(&$dbConfig)); + + $dbConfig['profiler'] = $config->Debug['enable_sql_profiler']; + + return $dbConfig; + } - $dbInfos['profiler'] = $config->Debug['enable_sql_profiler']; + /** + * Connects to the database. + * + * Shouldn't be called directly, use {@link get()} instead. + * + * @param array|null $dbConfig Connection parameters in an array. Defaults to the `[database]` + * INI config section. + */ + public static function createDatabaseObject($dbConfig = null) + { + $dbConfig = self::getDbConfig($dbConfig); - $adapter = $dbInfos['adapter']; - $db = @Adapter::factory($adapter, $dbInfos); + $db = @Adapter::factory($dbConfig['adapter'], $dbConfig); self::$connection = $db; } @@ -290,21 +297,21 @@ class Db } // filter out all InnoDB tables - $nonInnoDbTables = array(); + $innoDbTables = array(); foreach (Db::fetchAll("SHOW TABLE STATUS") as $row) { - if (strtolower($row['Engine']) != 'innodb' + if (strtolower($row['Engine']) == 'innodb' && in_array($row['Name'], $tables) ) { - $nonInnoDbTables[] = $row['Name']; + $innoDbTables[] = $row['Name']; } } - if (empty($nonInnoDbTables)) { + if (empty($innoDbTables)) { return false; } // optimize the tables - return self::query("OPTIMIZE TABLE " . implode(',', $nonInnoDbTables)); + return self::query("OPTIMIZE TABLE " . implode(',', $innoDbTables)); } /** diff --git a/core/Db/Adapter.php b/core/Db/Adapter.php index 71014ee2df796286001339fe750767c7fb4021b8..ea01773326542b2480c2096c44f9b6d2eb283069 100644 --- a/core/Db/Adapter.php +++ b/core/Db/Adapter.php @@ -42,15 +42,7 @@ class Adapter $className = self::getAdapterClassName($adapterName); Loader::loadClass($className); - /* - * 5.2.1 fixes various bugs with references that caused PDO_MYSQL getConnection() - * to clobber $dbInfos. (#33282, #35106, #39944) - */ - if (version_compare(PHP_VERSION, '5.2.1') < 0) { - $adapter = new $className(array_map('trim', $dbInfos)); - } else { - $adapter = new $className($dbInfos); - } + $adapter = new $className($dbInfos); if ($connect) { $adapter->getConnection(); diff --git a/core/Db/Schema.php b/core/Db/Schema.php index 4561a8414ba515cb6a21cfd47cefa34dec443bdf..ff9854b910d0607c10433a23b9a18eeba4a3bc51 100644 --- a/core/Db/Schema.php +++ b/core/Db/Schema.php @@ -51,7 +51,7 @@ class Schema extends Singleton static $allSchemaNames = array( // MySQL storage engines 'MYSQL' => array( - 'Myisam', + 'Mysql', // 'Innodb', // 'Infinidb', ), @@ -115,7 +115,7 @@ class Schema extends Singleton if (isset($dbInfos['schema'])) { $schemaName = $dbInfos['schema']; } else { - $schemaName = 'Myisam'; + $schemaName = 'Mysql'; } $className = self::getSchemaClassName($schemaName); $this->schema = new $className(); @@ -155,6 +155,17 @@ class Schema extends Singleton return $this->getSchema()->getTablesCreateSql(); } + /** + * Creates a new table in the database. + * + * @param string $nameWithoutPrefix The name of the table without any piwik prefix. + * @param string $createDefinition The table create definition + */ + public function createTable($nameWithoutPrefix, $createDefinition) + { + $this->getSchema()->createTable($nameWithoutPrefix, $createDefinition); + } + /** * Create database * diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Mysql.php similarity index 87% rename from core/Db/Schema/Myisam.php rename to core/Db/Schema/Mysql.php index a4652776f219aa523f72238e89ac90e090414d0c..08b7312f659ef46da7f8fc1b5e2b377c3c219ad9 100644 --- a/core/Db/Schema/Myisam.php +++ b/core/Db/Schema/Mysql.php @@ -10,7 +10,6 @@ namespace Piwik\Db\Schema; use Exception; use Piwik\Common; -use Piwik\Config; use Piwik\Date; use Piwik\Db\SchemaInterface; use Piwik\Db; @@ -19,7 +18,7 @@ use Piwik\DbHelper; /** * MySQL schema */ -class Myisam implements SchemaInterface +class Mysql implements SchemaInterface { /** * Is this MySQL storage engine available? @@ -45,7 +44,7 @@ class Myisam implements SchemaInterface */ static public function isAvailable() { - return self::hasStorageEngine('MyISAM'); + return self::hasStorageEngine('InnoDB'); } /** @@ -55,8 +54,9 @@ class Myisam implements SchemaInterface */ public function getTablesCreateSql() { - $config = Config::getInstance(); - $prefixTables = $config->database['tables_prefix']; + $engine = $this->getTableEngine(); + $prefixTables = $this->getTablePrefix(); + $tables = array( 'user' => "CREATE TABLE {$prefixTables}user ( login VARCHAR(100) NOT NULL, @@ -68,7 +68,7 @@ class Myisam implements SchemaInterface date_registered TIMESTAMP NULL, PRIMARY KEY(login), UNIQUE KEY uniq_keytoken(token_auth) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'access' => "CREATE TABLE {$prefixTables}access ( @@ -76,7 +76,7 @@ class Myisam implements SchemaInterface idsite INTEGER UNSIGNED NOT NULL, access VARCHAR(10) NULL, PRIMARY KEY(login, idsite) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'site' => "CREATE TABLE {$prefixTables}site ( @@ -97,14 +97,14 @@ class Myisam implements SchemaInterface `type` VARCHAR(255) NOT NULL, keep_url_fragment TINYINT NOT NULL DEFAULT 0, PRIMARY KEY(idsite) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'site_url' => "CREATE TABLE {$prefixTables}site_url ( idsite INTEGER(10) UNSIGNED NOT NULL, url VARCHAR(255) NOT NULL, PRIMARY KEY(idsite, url) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'goal' => " CREATE TABLE `{$prefixTables}goal` ( @@ -119,7 +119,7 @@ class Myisam implements SchemaInterface `revenue` float NOT NULL, `deleted` tinyint(4) NOT NULL default '0', PRIMARY KEY (`idsite`,`idgoal`) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'logger_message' => "CREATE TABLE {$prefixTables}logger_message ( @@ -129,7 +129,7 @@ class Myisam implements SchemaInterface level VARCHAR(16) NULL, message TEXT NULL, PRIMARY KEY(idlogger_message) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", @@ -141,7 +141,7 @@ class Myisam implements SchemaInterface url_prefix TINYINT(2) NULL, PRIMARY KEY(idaction), INDEX index_type_hash (type, hash) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'log_visit' => "CREATE TABLE {$prefixTables}log_visit ( @@ -206,7 +206,7 @@ class Myisam implements SchemaInterface INDEX index_idsite_config_datetime (idsite, config_id, visit_last_action_time), INDEX index_idsite_datetime (idsite, visit_last_action_time), INDEX index_idsite_idvisitor (idsite, idvisitor) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'log_conversion_item' => "CREATE TABLE `{$prefixTables}log_conversion_item` ( @@ -229,7 +229,7 @@ class Myisam implements SchemaInterface PRIMARY KEY(idvisit, idorder, idaction_sku), INDEX index_idsite_servertime ( idsite, server_time ) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'log_conversion' => "CREATE TABLE `{$prefixTables}log_conversion` ( @@ -277,7 +277,7 @@ class Myisam implements SchemaInterface PRIMARY KEY (idvisit, idgoal, buster), UNIQUE KEY unique_idsite_idorder (idsite, idorder), INDEX index_idsite_datetime ( idsite, server_time ) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'log_link_visit_action' => "CREATE TABLE {$prefixTables}log_link_visit_action ( @@ -307,7 +307,7 @@ class Myisam implements SchemaInterface PRIMARY KEY(idlink_va), INDEX index_idvisit(idvisit), INDEX index_idsite_servertime ( idsite, server_time ) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'log_profiling' => "CREATE TABLE {$prefixTables}log_profiling ( @@ -315,7 +315,7 @@ class Myisam implements SchemaInterface count INTEGER UNSIGNED NULL, sum_time_ms FLOAT NULL, UNIQUE KEY query(query(100)) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'option' => "CREATE TABLE `{$prefixTables}option` ( @@ -324,7 +324,7 @@ class Myisam implements SchemaInterface autoload TINYINT NOT NULL DEFAULT '1', PRIMARY KEY ( option_name ), INDEX autoload( autoload ) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'session' => "CREATE TABLE {$prefixTables}session ( @@ -333,7 +333,7 @@ class Myisam implements SchemaInterface lifetime INTEGER, data TEXT, PRIMARY KEY ( id ) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'archive_numeric' => "CREATE TABLE {$prefixTables}archive_numeric ( @@ -348,7 +348,7 @@ class Myisam implements SchemaInterface PRIMARY KEY(idarchive, name), INDEX index_idsite_dates_period(idsite, date1, date2, period, ts_archived), INDEX index_period_archived(period, ts_archived) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", 'archive_blob' => "CREATE TABLE {$prefixTables}archive_blob ( @@ -362,7 +362,7 @@ class Myisam implements SchemaInterface value MEDIUMBLOB NULL, PRIMARY KEY(idarchive, name), INDEX index_period_archived(period, ts_archived) - ) DEFAULT CHARSET=utf8 + ) ENGINE=$engine DEFAULT CHARSET=utf8 ", ); return $tables; @@ -395,8 +395,7 @@ class Myisam implements SchemaInterface public function getTablesNames() { $aTables = array_keys($this->getTablesCreateSql()); - $config = Config::getInstance(); - $prefixTables = $config->database['tables_prefix']; + $prefixTables = $this->getTablePrefix(); $return = array(); foreach ($aTables as $table) { $return[] = $prefixTables . $table; @@ -418,8 +417,7 @@ class Myisam implements SchemaInterface || $forceReload === true ) { $db = Db::get(); - $config = Config::getInstance(); - $prefixTables = $config->database['tables_prefix']; + $prefixTables = $this->getTablePrefix(); // '_' matches any character; force it to be literal $prefixTables = str_replace('_', '\_', $prefixTables); @@ -461,18 +459,43 @@ class Myisam implements SchemaInterface public function createDatabase($dbName = null) { if (is_null($dbName)) { - $dbName = Config::getInstance()->database['dbname']; + $dbName = $this->getDbName(); } Db::exec("CREATE DATABASE IF NOT EXISTS " . $dbName . " DEFAULT CHARACTER SET utf8"); } + /** + * Creates a new table in the database. + * + * @param string $nameWithoutPrefix The name of the table without any piwik prefix. + * @param string $createDefinition The table create definition, see the "MySQL CREATE TABLE" specification for + * more information. + * @throws \Exception + */ + public function createTable($nameWithoutPrefix, $createDefinition) + { + $statement = sprintf("CREATE TABLE `%s` ( %s ) ENGINE=%s DEFAULT CHARSET=utf8 ;", + Common::prefixTable($nameWithoutPrefix), + $createDefinition, + $this->getTableEngine()); + + try { + Db::exec($statement); + } catch (Exception $e) { + // mysql code error 1050:table already exists + // see bug #153 http://dev.piwik.org/trac/ticket/153 + if (!Db::get()->isErrNo($e, '1050')) { + throw $e; + } + } + } + /** * Drop database */ public function dropDatabase() { - $dbName = Config::getInstance()->database['dbname']; - Db::exec("DROP DATABASE IF EXISTS " . $dbName); + Db::exec("DROP DATABASE IF EXISTS " . $this->getDbName()); } /** @@ -481,8 +504,7 @@ class Myisam implements SchemaInterface public function createTables() { $db = Db::get(); - $config = Config::getInstance(); - $prefixTables = $config->database['tables_prefix']; + $prefixTables = $this->getTablePrefix(); $tablesAlreadyInstalled = $this->getTablesInstalled(); $tablesToCreate = $this->getTablesCreateSql(); @@ -542,4 +564,27 @@ class Myisam implements SchemaInterface } } } + + private function getTablePrefix() + { + $dbInfos = Db::getDbConfig(); + $prefixTables = $dbInfos['tables_prefix']; + + return $prefixTables; + } + + private function getTableEngine() + { + $dbInfos = Db::getDbConfig(); + $engine = $dbInfos['type']; + return $engine; + } + + private function getDbName() + { + $dbInfos = Db::getDbConfig(); + $dbName = $dbInfos['dbname']; + + return $dbName; + } } diff --git a/core/Db/SchemaInterface.php b/core/Db/SchemaInterface.php index 7acf9cf2ef75d3f5f067b7847d5f5e8e7803f33d..18888fae7ba8f2cc88d4e9c1269de3d9b5d5e46c 100644 --- a/core/Db/SchemaInterface.php +++ b/core/Db/SchemaInterface.php @@ -36,6 +36,14 @@ interface SchemaInterface */ public function getTablesCreateSql(); + /** + * Creates a new table in the database. + * + * @param string $nameWithoutPrefix The name of the table without any piwik prefix. + * @param string $createDefinition The table create definition + */ + public function createTable($nameWithoutPrefix, $createDefinition); + /** * Create database * diff --git a/core/DbHelper.php b/core/DbHelper.php index 56dab6de98e17552cb7c202614e24dfbee67ad26..01237cc02a7374c52e8f2d0caf908e92d73e601c 100644 --- a/core/DbHelper.php +++ b/core/DbHelper.php @@ -12,6 +12,9 @@ use Exception; use Piwik\Db\Adapter; use Piwik\Db\Schema; +/** + * Contains database related helper functions. + */ class DbHelper { /** @@ -25,6 +28,27 @@ class DbHelper return Schema::getInstance()->getTablesInstalled($forceReload); } + /** + * Creates a new table in the database. + * + * Example: + * ``` + * $tableDefinition = "`age` INT(11) NOT NULL AUTO_INCREMENT, + * `name` VARCHAR(255) NOT NULL"; + * + * DbHelper::createTable('tablename', $tableDefinition); + * `` + * + * @param string $nameWithoutPrefix The name of the table without any piwik prefix. + * @param string $createDefinition The table create definition + * + * @api + */ + public static function createTable($nameWithoutPrefix, $createDefinition) + { + Schema::getInstance()->createTable($nameWithoutPrefix, $createDefinition); + } + /** * Drop specific tables * @@ -146,4 +170,5 @@ class DbHelper { return Schema::getInstance()->getTableCreateSql($tableName); } + } diff --git a/misc/others/test_generateLotsVisitsWebsites.php b/misc/others/test_generateLotsVisitsWebsites.php index 84a7f7c577b7a6d3a00851ee843b48abdb5b5db5..4dd23c5f5148ea83f32272e3ceed7feb4d203ade 100644 --- a/misc/others/test_generateLotsVisitsWebsites.php +++ b/misc/others/test_generateLotsVisitsWebsites.php @@ -112,8 +112,15 @@ class Piwik_StressTests_CopyLogs WHERE date(server_time) = CURRENT_DATE();"; $db->query($sql); } - $sql = "OPTIMIZE TABLE " . Common::prefixTable('log_link_visit_action') . ", " . Common::prefixTable('log_conversion') . ", " . Common::prefixTable('log_conversion_item') . ", " . Common::prefixTable('log_visit') . ""; - $db->query($sql); + + $tablesToOptimize = array( + Common::prefixTable('log_link_visit_action'), + Common::prefixTable('log_conversion'), + Common::prefixTable('log_conversion_item'), + Common::prefixTable('log_visit') + ); + \Piwik\Db::optimizeTables($tablesToOptimize); + $this->log("done"); } diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php index 6b88da7e6e1032b9702b08e6cb1d49be06532c0c..94fbbf6b86064e7807a0e5f6b5ce320a44d4f82b 100644 --- a/plugins/Dashboard/Dashboard.php +++ b/plugins/Dashboard/Dashboard.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\Dashboard; use Exception; use Piwik\Common; use Piwik\Db; +use Piwik\DbHelper; use Piwik\Menu\MenuMain; use Piwik\Menu\MenuTop; use Piwik\Piwik; @@ -249,23 +250,13 @@ class Dashboard extends \Piwik\Plugin public function install() { - // we catch the exception - try { - $sql = "CREATE TABLE " . Common::prefixTable('user_dashboard') . " ( - login VARCHAR( 100 ) NOT NULL , - iddashboard INT NOT NULL , - name VARCHAR( 100 ) NULL DEFAULT NULL , - layout TEXT NOT NULL, - PRIMARY KEY ( login , iddashboard ) - ) DEFAULT CHARSET=utf8 "; - Db::exec($sql); - } catch (Exception $e) { - // mysql code error 1050:table already exists - // see bug #153 http://dev.piwik.org/trac/ticket/153 - if (!Db::get()->isErrNo($e, '1050')) { - throw $e; - } - } + $dashboard = "login VARCHAR( 100 ) NOT NULL , + iddashboard INT NOT NULL , + name VARCHAR( 100 ) NULL DEFAULT NULL , + layout TEXT NOT NULL, + PRIMARY KEY ( login , iddashboard )"; + + DbHelper::createTable('user_dashboard', $dashboard); } public function uninstall() diff --git a/plugins/Installation/FormDatabaseSetup.php b/plugins/Installation/FormDatabaseSetup.php index a9325171be8d55d9a927e8bec39eeda828240e39..0e5413c56c77f22f45ae5aad1b65aeefeeb33603 100644 --- a/plugins/Installation/FormDatabaseSetup.php +++ b/plugins/Installation/FormDatabaseSetup.php @@ -12,6 +12,7 @@ use Exception; use HTML_QuickForm2_DataSource_Array; use HTML_QuickForm2_Factory; use HTML_QuickForm2_Rule; +use Piwik\Config; use Piwik\Db\Adapter; use Piwik\Db; use Piwik\DbHelper; @@ -106,6 +107,7 @@ class FormDatabaseSetup extends QuickForm2 'tables_prefix' => $this->getSubmitValue('tables_prefix'), 'adapter' => $adapter, 'port' => $port, + 'type' => Config::getInstance()->database['type'] ); if (($portIndex = strpos($dbInfos['host'], '/')) !== false) { diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php index 3be1c000aa38d3c5f98533f006c1ea2e07071632..449d77987db1cc2fa1bef6e95f66e83a59056473 100644 --- a/plugins/LanguagesManager/LanguagesManager.php +++ b/plugins/LanguagesManager/LanguagesManager.php @@ -15,6 +15,7 @@ use Piwik\Config; use Piwik\Cookie; use Piwik\Db; +use Piwik\DbHelper; use Piwik\Menu\MenuTop; use Piwik\Piwik; use Piwik\Translate; @@ -114,21 +115,10 @@ class LanguagesManager extends \Piwik\Plugin */ public function install() { - // we catch the exception - try { - $sql = "CREATE TABLE " . Common::prefixTable('user_language') . " ( - login VARCHAR( 100 ) NOT NULL , - language VARCHAR( 10 ) NOT NULL , - PRIMARY KEY ( login ) - ) DEFAULT CHARSET=utf8 "; - Db::exec($sql); - } catch (Exception $e) { - // mysql code error 1050:table already exists - // see bug #153 http://dev.piwik.org/trac/ticket/153 - if (!Db::get()->isErrNo($e, '1050')) { - throw $e; - } - } + $userLanguage = "login VARCHAR( 100 ) NOT NULL , + language VARCHAR( 10 ) NOT NULL , + PRIMARY KEY ( login )"; + DbHelper::createTable('user_language', $userLanguage); } /** diff --git a/plugins/ScheduledReports/ScheduledReports.php b/plugins/ScheduledReports/ScheduledReports.php index 9d637832a0810dcd8a6b6638f9f829fbdc117383..9deaa618dd2b9a1f0be6ce6c4a190a23ad6d741b 100644 --- a/plugins/ScheduledReports/ScheduledReports.php +++ b/plugins/ScheduledReports/ScheduledReports.php @@ -13,6 +13,7 @@ use Piwik\Common; use Piwik\Config; use Piwik\Date; use Piwik\Db; +use Piwik\DbHelper; use Piwik\Mail; use Piwik\Menu\MenuTop; use Piwik\Piwik; @@ -550,33 +551,23 @@ class ScheduledReports extends \Piwik\Plugin public function install() { - $queries[] = ' - CREATE TABLE `' . Common::prefixTable('report') . '` ( - `idreport` INT(11) NOT NULL AUTO_INCREMENT, - `idsite` INTEGER(11) NOT NULL, - `login` VARCHAR(100) NOT NULL, - `description` VARCHAR(255) NOT NULL, - `idsegment` INT(11), - `period` VARCHAR(10) NOT NULL, - `hour` tinyint NOT NULL default 0, - `type` VARCHAR(10) NOT NULL, - `format` VARCHAR(10) NOT NULL, - `reports` TEXT NOT NULL, - `parameters` TEXT NULL, - `ts_created` TIMESTAMP NULL, - `ts_last_sent` TIMESTAMP NULL, - `deleted` tinyint(4) NOT NULL default 0, - PRIMARY KEY (`idreport`) - ) DEFAULT CHARSET=utf8'; - try { - foreach ($queries as $query) { - Db::exec($query); - } - } catch (Exception $e) { - if (!Db::get()->isErrNo($e, '1050')) { - throw $e; - } - } + $reportTable = "`idreport` INT(11) NOT NULL AUTO_INCREMENT, + `idsite` INTEGER(11) NOT NULL, + `login` VARCHAR(100) NOT NULL, + `description` VARCHAR(255) NOT NULL, + `idsegment` INT(11), + `period` VARCHAR(10) NOT NULL, + `hour` tinyint NOT NULL default 0, + `type` VARCHAR(10) NOT NULL, + `format` VARCHAR(10) NOT NULL, + `reports` TEXT NOT NULL, + `parameters` TEXT NULL, + `ts_created` TIMESTAMP NULL, + `ts_last_sent` TIMESTAMP NULL, + `deleted` tinyint(4) NOT NULL default 0, + PRIMARY KEY (`idreport`)"; + + DbHelper::createTable('report', $reportTable); } private static function checkAdditionalEmails($additionalEmails) diff --git a/plugins/SegmentEditor/SegmentEditor.php b/plugins/SegmentEditor/SegmentEditor.php index 7e72517a5e3c210613247ec40b56075e9f3c1784..3a8d644b1c3afc34c5f2eb8f49192e16a40ea6ba 100644 --- a/plugins/SegmentEditor/SegmentEditor.php +++ b/plugins/SegmentEditor/SegmentEditor.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\SegmentEditor; use Exception; use Piwik\Common; use Piwik\Db; +use Piwik\DbHelper; use Piwik\Version; /** @@ -71,28 +72,19 @@ class SegmentEditor extends \Piwik\Plugin public function install() { - $queries[] = 'CREATE TABLE `' . Common::prefixTable('segment') . '` ( - `idsegment` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(255) NOT NULL, - `definition` TEXT NOT NULL, - `login` VARCHAR(100) NOT NULL, - `enable_all_users` tinyint(4) NOT NULL default 0, - `enable_only_idsite` INTEGER(11) NULL, - `auto_archive` tinyint(4) NOT NULL default 0, - `ts_created` TIMESTAMP NULL, - `ts_last_edit` TIMESTAMP NULL, - `deleted` tinyint(4) NOT NULL default 0, - PRIMARY KEY (`idsegment`) - ) DEFAULT CHARSET=utf8'; - try { - foreach ($queries as $query) { - Db::exec($query); - } - } catch (Exception $e) { - if (!Db::get()->isErrNo($e, '1050')) { - throw $e; - } - } + $segmentTable = "`idsegment` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + `definition` TEXT NOT NULL, + `login` VARCHAR(100) NOT NULL, + `enable_all_users` tinyint(4) NOT NULL default 0, + `enable_only_idsite` INTEGER(11) NULL, + `auto_archive` tinyint(4) NOT NULL default 0, + `ts_created` TIMESTAMP NULL, + `ts_last_edit` TIMESTAMP NULL, + `deleted` tinyint(4) NOT NULL default 0, + PRIMARY KEY (`idsegment`)"; + + DbHelper::createTable('segment', $segmentTable); } public function getJsFiles(&$jsFiles)