/** * Returns the table name prefixed by the table prefix. * Works in both Tracker and UI mode. * * @param string $table The table name to prefix, ie "log_visit" * @return string The table name prefixed, ie "piwik-production_log_visit" */ public static function prefixTable($table) { if (is_null(self::$cachedTablePrefix)) { self::$cachedTablePrefix = Piwik_Config::getInstance()->database['tables_prefix']; } return self::$cachedTablePrefix . $table; }
public function setUp() { $dumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql.gz'; $deflatedDumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql'; $bufferSize = 1024 * 1024; // drop all tables Piwik::dropTables(); // download data dump $dump = fopen(self::$dumpUrl, 'rb'); $outfile = fopen($dumpPath, 'wb'); $bytesRead = 0; while (!feof($dump)) { fwrite($outfile, fread($dump, $bufferSize), $bufferSize); $bytesRead += $bufferSize; } fclose($dump); fclose($outfile); if ($bytesRead <= 40 * 1024 * 1024) { throw new Exception("Could not download sql dump!"); } // unzip the dump exec("gunzip -c \"" . $dumpPath . "\" > \"{$deflatedDumpPath}\"", $output, $return); if ($return !== 0) { throw new Exception("gunzip failed: " . implode("\n", $output)); } // load the data into the correct database $user = Piwik_Config::getInstance()->database['username']; $password = Piwik_Config::getInstance()->database['password']; $dbName = Piwik_Config::getInstance()->database['dbname']; Piwik_Config::getInstance()->database['tables_prefix'] = 'piwik_'; Piwik_Common::$cachedTablePrefix = null; exec("mysql -u \"{$user}\" \"--password={$password}\" {$dbName} < \"" . $deflatedDumpPath . "\" 2>&1", $output, $return); if ($return !== 0) { throw new Exception("Failed to load sql dump: " . implode("\n", $output)); } // make sure archiving will be called Piwik_ArchiveProcessing::setBrowserTriggerArchiving(true); }
public static function setUpBeforeClass() { $dbName = false; if (!empty($GLOBALS['PIWIK_BENCHMARK_DATABASE'])) { $dbName = $GLOBALS['PIWIK_BENCHMARK_DATABASE']; } // connect to database self::createTestConfig(); self::connectWithoutDatabase(); // create specified fixture (global var not set, use default no-data fixture (see end of this file)) if (empty($GLOBALS['PIWIK_BENCHMARK_FIXTURE'])) { $fixtureName = 'Piwik_Test_Fixture_EmptyOneSite'; } else { $fixtureName = 'Piwik_Test_Fixture_' . $GLOBALS['PIWIK_BENCHMARK_FIXTURE']; } self::$fixture = new $fixtureName(); // figure out if the desired fixture has already been setup, and if not empty the database $installedFixture = false; try { if (isset(self::$fixture->tablesPrefix)) { Piwik_Config::getInstance()->database['tables_prefix'] = self::$fixture->tablesPrefix; Piwik_Common::$cachedTablePrefix = null; } Piwik_Query("USE " . $dbName); $installedFixture = Piwik_GetOption('benchmark_fixture_name'); } catch (Exception $ex) { // ignore } $createEmptyDatabase = $fixtureName != $installedFixture; parent::setUpBeforeClass($dbName, $createEmptyDatabase, $createConfig = false); // if we created an empty database, setup the fixture if ($createEmptyDatabase) { self::$fixture->setUp(); Piwik_SetOption('benchmark_fixture_name', $fixtureName); } }