/** * Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs, * as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs. * * @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name * @param array $fields array of unquoted field names * @param array $values array of data to be inserted * @param bool $throwException Whether to throw an exception that was caught while trying * LOAD DATA INFILE, or not. * @throws Exception * @return bool True if the bulk LOAD was used, false if we fallback to plain INSERTs */ public static function tableInsertBatch($tableName, $fields, $values, $throwException = false) { $filePath = PIWIK_USER_PATH . '/tmp/assets/' . $tableName . '-' . Common::generateUniqId() . '.csv'; $filePath = SettingsPiwik::rewriteTmpPathWithInstanceId($filePath); $loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile']; if ($loadDataInfileEnabled && Db::get()->hasBulkLoader()) { try { $fileSpec = array('delim' => "\t", 'quote' => '"', 'escape' => '\\\\', 'escapespecial_cb' => function ($str) { return str_replace(array(chr(92), chr(34)), array(chr(92) . chr(92), chr(92) . chr(34)), $str); }, 'eol' => "\r\n", 'null' => 'NULL'); // hack for charset mismatch if (!DbHelper::isDatabaseConnectionUTF8() && !isset(Config::getInstance()->database['charset'])) { $fileSpec['charset'] = 'latin1'; } self::createCSVFile($filePath, $fileSpec, $values); if (!is_readable($filePath)) { throw new Exception("File {$filePath} could not be read."); } $rc = self::createTableFromCSVFile($tableName, $fields, $filePath, $fileSpec); if ($rc) { unlink($filePath); return true; } } catch (Exception $e) { Log::info("LOAD DATA INFILE failed or not supported, falling back to normal INSERTs... Error was: %s", $e->getMessage()); if ($throwException) { throw $e; } } } // if all else fails, fallback to a series of INSERTs @unlink($filePath); self::tableInsertBatchIterate($tableName, $fields, $values); return false; }
protected function makeUpdate(InputInterface $input, OutputInterface $output, $doDryRun) { $this->checkAllRequiredOptionsAreNotEmpty($input); $updater = $this->makeUpdaterInstance($output); $componentsWithUpdateFile = $updater->getComponentUpdates(); if (empty($componentsWithUpdateFile)) { throw new NoUpdatesFoundException("Everything is already up to date."); } $output->writeln(array("", " *** " . Piwik::translate('CoreUpdater_UpdateTitle') . " ***")); // handle case of existing database with no tables if (!DbHelper::isInstalled()) { $this->handleCoreError($output, Piwik::translate('CoreUpdater_EmptyDatabaseError', Config::getInstance()->database['dbname'])); return; } $output->writeln(array("", " " . Piwik::translate('CoreUpdater_DatabaseUpgradeRequired'), "", " " . Piwik::translate('CoreUpdater_YourDatabaseIsOutOfDate'))); if ($this->isUpdatingCore($componentsWithUpdateFile)) { $currentVersion = $this->getCurrentVersionForCore($updater); $output->writeln(array("", " " . Piwik::translate('CoreUpdater_PiwikWillBeUpgradedFromVersionXToVersionY', array($currentVersion, Version::VERSION)))); } $pluginsToUpdate = $this->getPluginsToUpdate($componentsWithUpdateFile); if (!empty($pluginsToUpdate)) { $output->writeln(array("", " " . Piwik::translate('CoreUpdater_TheFollowingPluginsWillBeUpgradedX', implode(', ', $pluginsToUpdate)))); } $dimensionsToUpdate = $this->getDimensionsToUpdate($componentsWithUpdateFile); if (!empty($dimensionsToUpdate)) { $output->writeln(array("", " " . Piwik::translate('CoreUpdater_TheFollowingDimensionsWillBeUpgradedX', implode(', ', $dimensionsToUpdate)))); } $output->writeln(""); if ($doDryRun) { $this->doDryRun($updater, $output); } else { $this->doRealUpdate($updater, $componentsWithUpdateFile, $output); } }
/** * Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs, * as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs. * * @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name * @param array $fields array of unquoted field names * @param array $values array of data to be inserted * @param bool $throwException Whether to throw an exception that was caught while trying * LOAD DATA INFILE, or not. * @throws Exception * @return bool True if the bulk LOAD was used, false if we fallback to plain INSERTs */ public static function tableInsertBatch($tableName, $fields, $values, $throwException = false) { $filePath = StaticContainer::get('path.tmp') . '/assets/' . $tableName . '-' . Common::generateUniqId() . '.csv'; $loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile']; if ($loadDataInfileEnabled && Db::get()->hasBulkLoader()) { try { $fileSpec = array('delim' => "\t", 'quote' => '"', 'escape' => '\\\\', 'escapespecial_cb' => function ($str) { return str_replace(array(chr(92), chr(34)), array(chr(92) . chr(92), chr(92) . chr(34)), $str); }, 'eol' => "\r\n", 'null' => 'NULL'); // hack for charset mismatch if (!DbHelper::isDatabaseConnectionUTF8() && !isset(Config::getInstance()->database['charset'])) { $fileSpec['charset'] = 'latin1'; } self::createCSVFile($filePath, $fileSpec, $values); if (!is_readable($filePath)) { throw new Exception("File {$filePath} could not be read."); } $rc = self::createTableFromCSVFile($tableName, $fields, $filePath, $fileSpec); if ($rc) { unlink($filePath); return true; } } catch (Exception $e) { if ($throwException) { throw $e; } } } // if all else fails, fallback to a series of INSERTs @unlink($filePath); self::tableInsertBatchIterate($tableName, $fields, $values); return false; }
public function getMigrations(Updater $updater) { $migrations = array($this->migration->db->addColumn('log_visit', 'visit_goal_converted', 'TINYINT( 1 ) NOT NULL', 'visit_total_time'), $this->migration->db->sql('CREATE TABLE `' . Common::prefixTable('goal') . "` (\n `idsite` int(11) NOT NULL,\n `idgoal` int(11) NOT NULL,\n `name` varchar(50) NOT NULL,\n `match_attribute` varchar(20) NOT NULL,\n `pattern` varchar(255) NOT NULL,\n `pattern_type` varchar(10) NOT NULL,\n `case_sensitive` tinyint(4) NOT NULL,\n `revenue` float NOT NULL,\n `deleted` tinyint(4) NOT NULL default '0',\n PRIMARY KEY (`idsite`,`idgoal`)\n )", Updater\Migration\Db::ERROR_CODE_TABLE_EXISTS), $this->migration->db->sql('CREATE TABLE `' . Common::prefixTable('log_conversion') . '` ( `idvisit` int(10) unsigned NOT NULL, `idsite` int(10) unsigned NOT NULL, `visitor_idcookie` char(32) NOT NULL, `server_time` datetime NOT NULL, `visit_server_date` date NOT NULL, `idaction` int(11) NOT NULL, `idlink_va` int(11) NOT NULL, `referer_idvisit` int(10) unsigned default NULL, `referer_type` int(10) unsigned default NULL, `referer_name` varchar(70) default NULL, `referer_keyword` varchar(255) default NULL, `visitor_returning` tinyint(1) NOT NULL, `location_country` char(3) NOT NULL, `location_continent` char(3) NOT NULL, `url` text NOT NULL, `idgoal` int(10) unsigned NOT NULL, `revenue` float default NULL, PRIMARY KEY (`idvisit`,`idgoal`), KEY `index_idsite_date` (`idsite`,`visit_server_date`) )', Updater\Migration\Db::ERROR_CODE_TABLE_EXISTS)); $tables = DbHelper::getTablesInstalled(); foreach ($tables as $tableName) { if (preg_match('/archive_/', $tableName) == 1) { $columns = array('idsite', 'date1', 'date2', 'name', 'ts_archived'); $tableNameUnprefixed = Common::unprefixTable($tableName); $migrations[] = $this->migration->db->addIndex($tableNameUnprefixed, $columns, 'index_all'); } } return $migrations; }
public function getMigrations(Updater $updater) { // Renaming old archived records now that the plugin is called Referrers $migrations = array(); $tables = \Piwik\DbHelper::getTablesInstalled(); foreach ($tables as $tableName) { if (strpos($tableName, 'archive_') !== false) { $migrations[] = $this->migration->db->sql('UPDATE `' . $tableName . '` SET `name`=REPLACE(`name`, \'Referers_\', \'Referrers_\') WHERE `name` LIKE \'Referers_%\''); } } $errorCodeTableNotFound = '1146'; // Rename custom segments containing Referers segments $migrations[] = $this->migration->db->sql('UPDATE `' . Common::prefixTable('segment') . '` SET `definition`=REPLACE(`definition`, \'referer\', \'referrer\') WHERE `definition` LIKE \'%referer%\'', $errorCodeTableNotFound); // Rename Referrers reports within scheduled reports $query = 'UPDATE `' . Common::prefixTable('report') . '` SET `reports`=REPLACE(`reports`, \'Referer\', \'Referrer\') WHERE `reports` LIKE \'%Referer%\''; $migrations[] = $this->migration->db->sql($query, $errorCodeTableNotFound); // Rename Referrers widgets in custom dashboards $query = 'UPDATE `' . Common::prefixTable('user_dashboard') . '` SET `layout`=REPLACE(`layout`, \'Referer\', \'Referrer\') WHERE `layout` LIKE \'%Referer%\''; $migrations[] = $this->migration->db->sql($query, $errorCodeTableNotFound); $query = 'UPDATE `' . Common::prefixTable('option') . '` SET `option_name` = \'version_ScheduledReports\' WHERE `option_name` = \'version_PDFReports\' '; $migrations[] = $this->migration->db->sql($query, Updater\Migration\Db::ERROR_CODE_DUPLICATE_ENTRY); // http://forum.piwik.org/read.php?2,106895 $migrations[] = $this->migration->plugin->activate('Referrers'); $migrations[] = $this->migration->plugin->activate('ScheduledReports'); return $migrations; }
public function getMigrationQueries(Updater $updater) { $sqlarray = array('ALTER TABLE `' . Common::prefixTable('log_visit') . '` ADD `visit_goal_converted` VARCHAR( 1 ) NOT NULL AFTER `visit_total_time`' => 1060, 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` CHANGE `visit_goal_converted` `visit_goal_converted` TINYINT(1) NOT NULL' => 1060, 'CREATE TABLE `' . Common::prefixTable('goal') . "` (\n\t\t\t\t`idsite` int(11) NOT NULL,\n\t\t\t\t`idgoal` int(11) NOT NULL,\n\t\t\t\t`name` varchar(50) NOT NULL,\n\t\t\t\t`match_attribute` varchar(20) NOT NULL,\n\t\t\t\t`pattern` varchar(255) NOT NULL,\n\t\t\t\t`pattern_type` varchar(10) NOT NULL,\n\t\t\t\t`case_sensitive` tinyint(4) NOT NULL,\n\t\t\t\t`revenue` float NOT NULL,\n\t\t\t\t`deleted` tinyint(4) NOT NULL default '0',\n\t\t\t\tPRIMARY KEY (`idsite`,`idgoal`)\n\t\t\t)" => 1050, 'CREATE TABLE `' . Common::prefixTable('log_conversion') . '` ( `idvisit` int(10) unsigned NOT NULL, `idsite` int(10) unsigned NOT NULL, `visitor_idcookie` char(32) NOT NULL, `server_time` datetime NOT NULL, `visit_server_date` date NOT NULL, `idaction` int(11) NOT NULL, `idlink_va` int(11) NOT NULL, `referer_idvisit` int(10) unsigned default NULL, `referer_type` int(10) unsigned default NULL, `referer_name` varchar(70) default NULL, `referer_keyword` varchar(255) default NULL, `visitor_returning` tinyint(1) NOT NULL, `location_country` char(3) NOT NULL, `location_continent` char(3) NOT NULL, `url` text NOT NULL, `idgoal` int(10) unsigned NOT NULL, `revenue` float default NULL, PRIMARY KEY (`idvisit`,`idgoal`), KEY `index_idsite_date` (`idsite`,`visit_server_date`) )' => 1050); $tables = DbHelper::getTablesInstalled(); foreach ($tables as $tableName) { if (preg_match('/archive_/', $tableName) == 1) { $sqlarray['CREATE INDEX index_all ON ' . $tableName . ' (`idsite`,`date1`,`date2`,`name`,`ts_archived`)'] = 1072; } } return $sqlarray; }
/** * Get the SQL to create a specific Piwik table * * @param string $tableName * @throws Exception * @return string SQL */ public function getTableCreateSql($tableName) { $tables = DbHelper::getTablesCreateSql(); if (!isset($tables[$tableName])) { throw new Exception("The table '{$tableName}' SQL creation code couldn't be found."); } return $tables[$tableName]; }
/** * @return string[] */ private function getDirectories() { $directoriesToCheck = array($this->tmpPath, $this->tmpPath . '/assets/', $this->tmpPath . '/cache/', $this->tmpPath . '/climulti/', $this->tmpPath . '/latest/', $this->tmpPath . '/logs/', $this->tmpPath . '/sessions/', $this->tmpPath . '/tcpdf/', $this->tmpPath . '/templates_c/'); if (!DbHelper::isInstalled()) { // at install, need /config to be writable (so we can create config.ini.php) $directoriesToCheck[] = '/config/'; } return $directoriesToCheck; }
public static function install() { $tableAlert = "`idalert` INT NOT NULL PRIMARY KEY ,\n `name` VARCHAR(100) NOT NULL ,\n `login` VARCHAR(100) NOT NULL ,\n `period` VARCHAR(5) NOT NULL ,\n `report` VARCHAR(150) NOT NULL ,\n `report_condition` VARCHAR(50) ,\n `report_matched` VARCHAR(255) ,\n `metric` VARCHAR(150) NOT NULL ,\n `metric_condition` VARCHAR(50) NOT NULL ,\n `metric_matched` FLOAT NOT NULL ,\n `compared_to` SMALLINT (4) UNSIGNED NOT NULL DEFAULT 1 ,\n `email_me` BOOLEAN NOT NULL DEFAULT '0',\n `additional_emails` TEXT ,\n `phone_numbers` TEXT "; DbHelper::createTable('alert', $tableAlert); $tableAlertSite = "`idalert` INT( 11 ) NOT NULL ,\n `idsite` INT( 11 ) NOT NULL ,\n PRIMARY KEY ( idalert, idsite )"; DbHelper::createTable('alert_site', $tableAlertSite); $tableAlertLog = "`idtriggered` BIGINT unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t `idalert` INT( 11 ) NOT NULL ,\n\t\t\t `idsite` INT( 11 ) NOT NULL ,\n\t\t\t `ts_triggered` timestamp NOT NULL default CURRENT_TIMESTAMP,\n\t\t\t `ts_last_sent` timestamp NULL DEFAULT NULL,\n\t\t\t `value_old` DECIMAL (20,3) DEFAULT NULL,\n\t\t\t `value_new` DECIMAL (20,3) DEFAULT NULL,\n `name` VARCHAR(100) NOT NULL ,\n\t\t\t `login` VARCHAR(100) NOT NULL ,\n\t\t\t `period` VARCHAR(5) NOT NULL ,\n\t\t\t `report` VARCHAR(150) NOT NULL ,\n\t\t\t `report_condition` VARCHAR(50) ,\n\t\t\t `report_matched` VARCHAR(1000) ,\n\t\t\t `metric` VARCHAR(150) NOT NULL ,\n\t\t\t `metric_condition` VARCHAR(50) NOT NULL ,\n\t\t\t `metric_matched` FLOAT NOT NULL ,\n\t\t\t `compared_to` SMALLINT NOT NULL DEFAULT 1 ,\n\t\t\t `email_me` BOOLEAN NOT NULL DEFAULT '0',\n\t\t\t `additional_emails` TEXT ,\n\t\t\t `phone_numbers` TEXT ,\n\t\t\t PRIMARY KEY (idtriggered)"; DbHelper::createTable('alert_triggered', $tableAlertLog); }
/** * anonymous = in the session * authenticated user = in the session */ public function saveLanguage() { $language = Common::getRequestVar('language'); // Prevent CSRF only when piwik is not installed yet (During install user can change language) if (DbHelper::isInstalled()) { $this->checkTokenInUrl(); } LanguagesManager::setLanguageForSession($language); Url::redirectToReferrer(); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); DbHelper::createAnonymousUser(); // the api_internal_call.php uses idSite=7, so we create 7 sites for ($i = 0; $i != 7; ++$i) { Fixture::createWebsite("2011-01-01 00:00:00", $ecommerce = 1, $siteName = "Site #{$i}"); } // the script uses anonymous token auth, so give the anonymous user access \Piwik\Plugins\UsersManager\API::getInstance()->setUserAccess('anonymous', 'view', array(7)); }
/** * Installs the plugin. Derived classes should implement this class if the plugin * needs to: * * - create tables * - update existing tables * - etc. * * @throws \Exception if installation of fails for some reason. */ public function install() { try { DbHelper::createTable('bannerstats', "\n `label` varchar(100) not null,\n `content_name_id` int not null,\n `impression` int not null,\n `interaction` int not null,\n `referrer` varchar(200),\n `target` varchar(200),\n `date` date,\n `custom_var_v1`\tvarchar(200),\n `custom_var_v2`\tvarchar(200),\n `custom_var_v3`\tvarchar(200),\n `custom_var_v4`\tvarchar(200),\n `custom_var_v5`\tvarchar(200),\n\n UNIQUE KEY `unique_combination` (`date`, `label`, `content_name_id`, `referrer`, `target`)\n "); } catch (Exception $e) { // ignore error if table already exists (1050 code is for 'table already exists') if (!Db::get()->isErrNo($e, '1050')) { throw $e; } } }
private function ensureTargetTableExists($archiveTable) { $data = $this->targetDb->getAdapter()->fetchCol("SHOW TABLES LIKE '" . $this->targetDb->prefixTable($archiveTable) . "'"); if (count($data) == 0) { $tableType = strpos($archiveTable, 'blob') ? 'archive_blob' : 'archive_numeric'; $sql = PiwikDbHelper::getTableCreateSql($tableType); $sql = str_replace($tableType, $archiveTable, $sql); $sql = str_replace($this->sourceDb->prefixTable($tableType), $this->targetDb->prefixTable($tableType), $sql); $this->targetDb->getAdapter()->query($sql); } }
public function setUp() { parent::setUp(); Option::set('version_core', self::VERSION_TO_UPDATE_FROM); $this->oldScriptName = $_SERVER['SCRIPT_NAME']; $_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_NAME'] . " console"; // update won't execute w/o this, see Common::isRunningConsoleCommand() ArchiveTableCreator::clear(); DbHelper::getTablesInstalled($forceReload = true); // force reload so internal cache in Mysql.php is refreshed Updates_2_10_0_b5::$archiveBlobTables = null; }
/** * @expectedException \Zend_Db_Statement_Exception * @expectedExceptionMessage custom_dimensions */ public function test_shouldBeAbleToUninstallConfigTable() { $this->config->uninstall(); try { DbHelper::getTableColumns($this->tableName); // doesn't work anymore as table was removed } catch (Zend_Db_Statement_Exception $e) { $this->config->install(); throw $e; } $this->config->install(); }
public function getMigrations(Updater $updater) { $migrations = array($this->migration->db->sql('ALTER TABLE `' . Common::prefixTable('user_dashboard') . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ', Updater\Migration\Db::ERROR_CODE_TABLE_NOT_EXISTS), $this->migration->db->sql('ALTER TABLE `' . Common::prefixTable('user_language') . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ', Updater\Migration\Db::ERROR_CODE_TABLE_NOT_EXISTS)); // alter table to set the utf8 collation $tablesToAlter = DbHelper::getTablesInstalled(true); foreach ($tablesToAlter as $table) { $migrations[] = $this->migration->db->sql('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci'); } return $migrations; }
public function setUp() { parent::setUp(); self::updateDatabase(); // make sure site has an early enough creation date (for period selector tests) Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1"); $this->addOverlayVisits(); $this->addNewSitesForSiteSelector(); DbHelper::createAnonymousUser(); UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true); SitesManagerAPI::getInstance()->updateSite(1, null, null, true); }
static function getSql() { $sqlarray = array('ALTER TABLE `' . Common::prefixTable('user_dashboard') . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ' => '1146', 'ALTER TABLE `' . Common::prefixTable('user_language') . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ' => '1146'); // alter table to set the utf8 collation $tablesToAlter = DbHelper::getTablesInstalled(true); foreach ($tablesToAlter as $table) { $sqlarray['ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci '] = false; } return $sqlarray; }
static function getSql() { $sqlarray = array('DROP INDEX index_idsite_date ON ' . Common::prefixTable('log_visit') => '1091', 'CREATE INDEX index_idsite_date_config ON ' . Common::prefixTable('log_visit') . ' (idsite, visit_server_date, config_md5config(8))' => '1061'); $tables = DbHelper::getTablesInstalled(); foreach ($tables as $tableName) { if (preg_match('/archive_/', $tableName) == 1) { $sqlarray['DROP INDEX index_all ON ' . $tableName] = '1091'; } if (preg_match('/archive_numeric_/', $tableName) == 1) { $sqlarray['CREATE INDEX index_idsite_dates_period ON ' . $tableName . ' (idsite, date1, date2, period)'] = '1061'; } } return $sqlarray; }
public function setUp() { parent::setUp(); // make sure site has an early enough creation date (for period selector tests) Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1"); $this->addOverlayVisits(); $this->addNewSitesForSiteSelector(); DbHelper::createAnonymousUser(); UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true); Option::set("Tests.forcedNowTimestamp", $this->now->getTimestamp()); // launch archiving so tests don't run out of time $date = Date::factory($this->dateTime)->toString(); VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date); VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date, urlencode($this->segment)); }
public function createArchiveTable($tableName, $tableNamePrefix) { $db = Db::get(); $sql = DbHelper::getTableCreateSql($tableNamePrefix); // replace table name template by real name $tableNamePrefix = Common::prefixTable($tableNamePrefix); $sql = str_replace($tableNamePrefix, $tableName, $sql); try { $db->query($sql); } catch (Exception $e) { // accept mysql error 1050: table already exists, throw otherwise if (!$db->isErrNo($e, '1050')) { throw $e; } } }
/** * anonymous = in the session * authenticated user = in the session and in DB */ public function saveLanguage() { $language = Common::getRequestVar('language'); // Prevent CSRF only when piwik is not installed yet (During install user can change language) if (DbHelper::isInstalled()) { $this->checkTokenInUrl(); } LanguagesManager::setLanguageForSession($language); if (\Piwik\Registry::isRegistered('access')) { $currentUser = Piwik::getCurrentUserLogin(); if ($currentUser && $currentUser !== 'anonymous') { API::getInstance()->setLanguageForUser($currentUser, $language); } } Url::redirectToReferrer(); }
public function getMigrations(Updater $updater) { $migrations = array($this->migration->db->dropIndex('log_visit', 'index_idsite_date'), $this->migration->db->addIndex('log_visit', array('idsite', 'visit_server_date', 'config_md5config(8)'), 'index_idsite_date_config')); $tables = DbHelper::getTablesInstalled(); foreach ($tables as $tableName) { $unprefixedTable = Common::unprefixTable($tableName); if (preg_match('/archive_/', $tableName) == 1) { $migrations[] = $this->migration->db->dropIndex($unprefixedTable, 'index_all'); } if (preg_match('/archive_numeric_/', $tableName) == 1) { $columns = array('idsite', 'date1', 'date2', 'period'); $migrations[] = $this->migration->db->addIndex($unprefixedTable, $columns, 'index_idsite_dates_period'); } } return $migrations; }
public function setUp() { parent::setUp(); // recreate log_visit/log_link_visit_action/log_conversion tables w/o any dimensions $tablesToRecreate = array('log_visit', 'log_link_visit_action', 'log_conversion'); foreach ($tablesToRecreate as $table) { Db::exec("DROP TABLE `" . Common::prefixTable($table) . "`"); $tableCreateSql = DbHelper::getTableCreateSql($table); Db::exec($tableCreateSql); } $visitDimensions = array($this->getMockVisitDimension("test_visit_col_1", "INTEGER(10) UNSIGNED NOT NULL"), $this->getMockVisitDimension("test_visit_col_2", "VARCHAR(32) NOT NULL")); $actionDimensions = array($this->getMockActionDimension("test_action_col_1", "VARCHAR(32) NOT NULL"), $this->getMockActionDimension("test_action_col_2", "INTEGER(10) UNSIGNED DEFAULT NULL")); $conversionDimensions = array($this->getMockConversionDimension("test_conv_col_1", "FLOAT DEFAULT NULL"), $this->getMockConversionDimension("test_conv_col_2", "VARCHAR(32) NOT NULL")); $this->columnsUpdater = new ColumnsUpdater($visitDimensions, $actionDimensions, $conversionDimensions); $this->tableColumnsCache = array(); }
public function setUp() { self::downloadGeoIpDbs(); parent::setUp(); self::updateDatabase(); // make sure site has an early enough creation date (for period selector tests) Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1"); // for proper geolocation LocationProvider::setCurrentProvider(LocationProvider\GeoIp\Php::ID); IPAnonymizer::deactivate(); $this->addOverlayVisits(); $this->addNewSitesForSiteSelector(); DbHelper::createAnonymousUser(); UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true); SitesManagerAPI::getInstance()->updateSite(1, null, null, true); // create non super user UsersManagerAPI::getInstance()->addUser('oliverqueen', 'smartypants', '*****@*****.**'); UsersManagerAPI::getInstance()->setUserAccess('oliverqueen', 'view', array(1)); }
public static function getSql() { // Renaming old archived records now that the plugin is called Referrers $sql = array(); $tables = \Piwik\DbHelper::getTablesInstalled(); foreach ($tables as $tableName) { if (strpos($tableName, 'archive_') !== false) { $sql['UPDATE `' . $tableName . '` SET `name`=REPLACE(`name`, \'Referers_\', \'Referrers_\') WHERE `name` LIKE \'Referers_%\''] = false; } } $errorCodeTableNotFound = '1146'; // Rename custom segments containing Referers segments $sql['UPDATE `' . Common::prefixTable('segment') . '` SET `definition`=REPLACE(`definition`, \'referer\', \'referrer\') WHERE `definition` LIKE \'%referer%\''] = $errorCodeTableNotFound; // Rename Referrers reports within scheduled reports $sql['UPDATE `' . Common::prefixTable('report') . '` SET `reports`=REPLACE(`reports`, \'Referer\', \'Referrer\') WHERE `reports` LIKE \'%Referer%\''] = $errorCodeTableNotFound; // Rename Referrers widgets in custom dashboards $sql['UPDATE `' . Common::prefixTable('user_dashboard') . '` SET `layout`=REPLACE(`layout`, \'Referer\', \'Referrer\') WHERE `layout` LIKE \'%Referer%\''] = $errorCodeTableNotFound; $sql['UPDATE `' . Common::prefixTable('option') . '` SET `option_name` = \'version_ScheduledReports\' WHERE `option_name` = \'version_PDFReports\' '] = '1062'; // http://forum.piwik.org/read.php?2,106895 return $sql; }
/** * Gets the result of a SHOW TABLE STATUS query for every Piwik table in the DB. * Non-piwik tables are ignored. * * @param string $matchingRegex Regex used to filter out tables whose name doesn't * match it. * @return array The table information. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html * for specifics. */ public function getAllTablesStatus($matchingRegex = null) { if (is_null($this->tableStatuses)) { $tablesPiwik = DbHelper::getTablesInstalled(); $this->tableStatuses = array(); foreach ($this->dataAccess->getAllTablesStatus() as $t) { if (in_array($t['Name'], $tablesPiwik)) { $this->tableStatuses[$t['Name']] = $t; } } } if (is_null($matchingRegex)) { return $this->tableStatuses; } $result = array(); foreach ($this->tableStatuses as $status) { if (preg_match($matchingRegex, $status['Name'])) { $result[] = $status; } } return $result; }
private function doWelcomeUpdates($view, $componentsWithUpdateFile) { $view->new_piwik_version = Version::VERSION; $view->commandUpgradePiwik = "<br /><code>php " . Filesystem::getPathToPiwikRoot() . "/console core:update </code>"; $pluginNamesToUpdate = array(); $dimensionsToUpdate = array(); $coreToUpdate = false; // handle case of existing database with no tables if (!DbHelper::isInstalled()) { $this->errorMessages[] = Piwik::translate('CoreUpdater_EmptyDatabaseError', Config::getInstance()->database['dbname']); $this->coreError = true; $currentVersion = 'N/A'; } else { $this->errorMessages = array(); try { $currentVersion = Option::get('version_core'); } catch (Exception $e) { $currentVersion = '<= 0.2.9'; } foreach ($componentsWithUpdateFile as $name => $filenames) { if ($name == 'core') { $coreToUpdate = true; } elseif (0 === strpos($name, 'log_')) { $dimensionsToUpdate[] = $name; } else { $pluginNamesToUpdate[] = $name; } } } // check file integrity $integrityInfo = Filechecks::getFileIntegrityInformation(); if (isset($integrityInfo[1])) { if ($integrityInfo[0] == false) { $this->warningMessages[] = Piwik::translate('General_FileIntegrityWarningExplanation'); } $this->warningMessages = array_merge($this->warningMessages, array_slice($integrityInfo, 1)); } Filesystem::deleteAllCacheOnUpdate(); $view->coreError = $this->coreError; $view->warningMessages = $this->warningMessages; $view->errorMessages = $this->errorMessages; $view->current_piwik_version = $currentVersion; $view->pluginNamesToUpdate = $pluginNamesToUpdate; $view->dimensionsToUpdate = $dimensionsToUpdate; $view->coreToUpdate = $coreToUpdate; }
public function onEnvironmentBootstrapped() { if (empty($_GET['ignoreClearAllViewDataTableParameters'])) { // TODO: should use testingEnvironment variable, not query param try { \Piwik\ViewDataTable\Manager::clearAllViewDataTableParameters(); } catch (\Exception $ex) { // ignore (in case DB is not setup) } } if ($this->vars->optionsOverride) { try { foreach ($this->vars->optionsOverride as $name => $value) { Option::set($name, $value); } } catch (\Exception $ex) { // ignore (in case DB is not setup) } } \Piwik\Plugins\CoreVisualizations\Visualizations\Cloud::$debugDisableShuffle = true; \Piwik\Visualization\Sparkline::$enableSparklineImages = false; \Piwik\Plugins\ExampleUI\API::$disableRandomness = true; if ($this->vars->deleteArchiveTables && !$this->vars->_archivingTablesDeleted) { $this->vars->_archivingTablesDeleted = true; DbHelper::deleteArchiveTables(); } }
/** * Write configuration file from session-store */ private function createConfigFile($dbInfos) { $config = Config::getInstance(); // make sure DB sessions are used if the filesystem is NFS if (Filesystem::checkIfFileSystemIsNFS()) { $config->General['session_save_handler'] = 'dbtable'; } if (count($headers = ProxyHeaders::getProxyClientHeaders()) > 0) { $config->General['proxy_client_headers'] = $headers; } if (count($headers = ProxyHeaders::getProxyHostHeaders()) > 0) { $config->General['proxy_host_headers'] = $headers; } if (Common::getRequestVar('clientProtocol', 'http', 'string') == 'https') { $protocol = 'https'; } else { $protocol = ProxyHeaders::getProtocolInformation(); } if (!empty($protocol) && !\Piwik\ProxyHttp::isHttps()) { $config->General['assume_secure_protocol'] = '1'; } $config->General['salt'] = Common::generateUniqId(); $config->General['installation_in_progress'] = 1; $config->database = $dbInfos; if (!DbHelper::isDatabaseConnectionUTF8()) { $config->database['charset'] = 'utf8'; } $config->forceSave(); }