public function test_purgeOutdatedArchives_Purges_WhenBrowserArchivingEnabled_AndCronArchiveTriggerPresent() { Rules::setBrowserTriggerArchiving(false); $_GET['trigger'] = 'archivephp'; $wasPurged = $this->tasks->purgeOutdatedArchives(); $this->assertTrue($wasPurged); }
/** * @internal */ public function setArchiveSettings($enableBrowserTriggerArchiving, $todayArchiveTimeToLive) { Piwik::checkUserHasSuperUserAccess(); if (!Controller::isGeneralSettingsAdminEnabled()) { throw new Exception('General settings admin is ont enabled'); } Rules::setBrowserTriggerArchiving((bool) $enableBrowserTriggerArchiving); Rules::setTodayArchiveTimeToLive($todayArchiveTimeToLive); return true; }
public function setUp() { // drop all tables Db::dropAllTables(); // download data dump if url supplied if (is_file($this->dumpUrl)) { $dumpPath = $this->dumpUrl; } else { $dumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql.gz'; $bufferSize = 1024 * 1024; $dump = fopen($this->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) { // sanity check throw new Exception("Could not download sql dump!"); } } // unzip the dump if (substr($dumpPath, -3) === ".gz") { $deflatedDumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql'; // TODO: should depend on name of URL exec("gunzip -c \"" . $dumpPath . "\" > \"{$deflatedDumpPath}\"", $output, $return); if ($return !== 0) { throw new Exception("gunzip failed: " . implode("\n", $output)); } } else { $deflatedDumpPath = $dumpPath; } // load the data into the correct database $user = Config::getInstance()->database['username']; $password = Config::getInstance()->database['password']; Config::getInstance()->database['tables_prefix'] = $this->tablesPrefix; $cmd = "mysql -u \"{$user}\" \"--password={$password}\" {$this->dbName} < \"" . $deflatedDumpPath . "\" 2>&1"; exec($cmd, $output, $return); if ($return !== 0) { throw new Exception("Failed to load sql dump: " . implode("\n", $output)); } // make sure archiving will be called Rules::setBrowserTriggerArchiving(true); // reload access Piwik::setUserHasSuperUserAccess(); $this->getTestEnvironment()->configOverride = array('database' => array('tables_prefix' => $this->tablesPrefix)); $this->getTestEnvironment()->save(); }
public function setUp() { // drop all tables Db::dropAllTables(); // download data dump if url supplied if (is_file($this->dumpUrl)) { $dumpPath = $this->dumpUrl; } else { $dumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql.gz'; $bytesRead = $this->downloadDumpInPath($dumpPath); // sanity check if ($bytesRead <= 40 * 1024 * 1024) { $str = "Could not download sql dump! You can manually download %s into %s"; throw new Exception(sprintf($str, $this->dumpUrl, $dumpPath)); } } // unzip the dump if (substr($dumpPath, -3) === ".gz") { $deflatedDumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql'; // TODO: should depend on name of URL exec("gunzip -c \"" . $dumpPath . "\" > \"{$deflatedDumpPath}\"", $output, $return); if ($return !== 0) { throw new Exception("gunzip failed: " . implode("\n", $output)); } } else { $deflatedDumpPath = $dumpPath; } // load the data into the correct database $user = Config::getInstance()->database['username']; $password = Config::getInstance()->database['password']; $host = Config::getInstance()->database['host']; Config::getInstance()->database['tables_prefix'] = $this->tablesPrefix; $cmd = "mysql -h \"{$host}\" -u \"{$user}\" \"--password={$password}\" {$this->dbName} < \"" . $deflatedDumpPath . "\" 2>&1"; exec($cmd, $output, $return); if ($return !== 0) { throw new Exception("Failed to load sql dump: " . implode("\n", $output)); } // make sure archiving will be called Rules::setBrowserTriggerArchiving(true); // reload access Access::getInstance()->reloadAccess(); $testVars = new TestingEnvironmentVariables(); $testVars->configOverride = array('database' => array('tables_prefix' => $this->tablesPrefix)); $testVars->save(); }
/** * test of validity of an archive, for today's archive with toronto's timezone * @group Core */ public function testInitTodayToronto() { if (!SettingsServer::isTimezoneSupportEnabled()) { $this->markTestSkipped('timezones needs to be supported'); } $now = time(); $siteTimezone = 'America/Toronto'; $timestamp = Date::factory('now', $siteTimezone)->getTimestamp(); $dateLabel = date('Y-m-d', $timestamp); Rules::setBrowserTriggerArchiving(true); $archiveProcessor = $this->_createArchiveProcessor('day', $dateLabel, $siteTimezone); $archiveProcessor->time = $now; // we look at anything processed within the time to live range $dateMinArchived = $now - Rules::getTodayArchiveTimeToLive(); $this->compareTimestamps($dateMinArchived, $archiveProcessor->public_getMinTimeArchiveProcessed()); $this->assertTrue($archiveProcessor->public_isArchiveTemporary()); // when browsers don't trigger archives... Rules::setBrowserTriggerArchiving(false); // ...we force ArchiveProcessor to fetch any of the most recent archive $dateMinArchived = false; $this->compareTimestamps($dateMinArchived, $archiveProcessor->public_getMinTimeArchiveProcessed()); // this test varies with DST $this->assertTrue($archiveProcessor->getParams()->getDateStart()->getDateStartUTC() == date('Y-m-d', $timestamp) . ' 04:00:00' || $archiveProcessor->getParams()->getDateStart()->getDateStartUTC() == date('Y-m-d', $timestamp) . ' 05:00:00'); $this->assertTrue($archiveProcessor->getParams()->getDateEnd()->getDateEndUTC() == date('Y-m-d', $timestamp + 86400) . ' 03:59:59' || $archiveProcessor->getParams()->getDateEnd()->getDateEndUTC() == date('Y-m-d', $timestamp + 86400) . ' 04:59:59'); $this->assertTrue($archiveProcessor->public_isArchiveTemporary()); }
private function saveGeneralSettings() { if (!self::isGeneralSettingsAdminEnabled()) { // General settings + Beta channel + SMTP settings is disabled return; } // General Setting $enableBrowserTriggerArchiving = Common::getRequestVar('enableBrowserTriggerArchiving'); $todayArchiveTimeToLive = Common::getRequestVar('todayArchiveTimeToLive'); Rules::setBrowserTriggerArchiving((bool) $enableBrowserTriggerArchiving); Rules::setTodayArchiveTimeToLive($todayArchiveTimeToLive); // update beta channel setting $debug = Config::getInstance()->Debug; $debug['allow_upgrades_to_beta'] = Common::getRequestVar('enableBetaReleaseCheck', '0', 'int'); Config::getInstance()->Debug = $debug; // Update email settings $mail = array(); $mail['transport'] = Common::getRequestVar('mailUseSmtp') == '1' ? 'smtp' : ''; $mail['port'] = Common::getRequestVar('mailPort', ''); $mail['host'] = Common::unsanitizeInputValue(Common::getRequestVar('mailHost', '')); $mail['type'] = Common::getRequestVar('mailType', ''); $mail['username'] = Common::unsanitizeInputValue(Common::getRequestVar('mailUsername', '')); $mail['password'] = Common::unsanitizeInputValue(Common::getRequestVar('mailPassword', '')); $mail['encryption'] = Common::getRequestVar('mailEncryption', ''); Config::getInstance()->mail = $mail; // update trusted host settings $trustedHosts = Common::getRequestVar('trustedHosts', false, 'json'); if ($trustedHosts !== false) { Url::saveTrustedHostnameInConfig($trustedHosts); } Config::getInstance()->forceSave(); $pluginUpdateCommunication = new UpdateCommunication(); if (Common::getRequestVar('enablePluginUpdateCommunication', '0', 'int')) { $pluginUpdateCommunication->enable(); } else { $pluginUpdateCommunication->disable(); } }
public function test_ArchiveIsLaunched_WhenForceOnBrowserRequest_IsFalse_AndArchivePhpTriggered() { $this->archiveDataForIndividualDays(); Config::getInstance()->General['archiving_range_force_on_browser_request'] = 0; $_GET['trigger'] = 'archivephp'; Rules::setBrowserTriggerArchiving(false); $data = $this->initiateArchivingForRange(); $this->assertNotEmpty($data); $this->assertArchiveTablesAreNotEmpty('2010_03'); }
private function saveGeneralSettings() { if (!$this->isGeneralSettingsAdminEnabled()) { // General settings + Beta channel + SMTP settings is disabled return; } // General Setting $enableBrowserTriggerArchiving = Common::getRequestVar('enableBrowserTriggerArchiving'); $todayArchiveTimeToLive = Common::getRequestVar('todayArchiveTimeToLive'); Rules::setBrowserTriggerArchiving((bool) $enableBrowserTriggerArchiving); Rules::setTodayArchiveTimeToLive($todayArchiveTimeToLive); // update beta channel setting $debug = Config::getInstance()->Debug; $debug['allow_upgrades_to_beta'] = Common::getRequestVar('enableBetaReleaseCheck', '0', 'int'); Config::getInstance()->Debug = $debug; // Update email settings $mail = array(); $mail['transport'] = Common::getRequestVar('mailUseSmtp') == '1' ? 'smtp' : ''; $mail['port'] = Common::getRequestVar('mailPort', ''); $mail['host'] = Common::unsanitizeInputValue(Common::getRequestVar('mailHost', '')); $mail['type'] = Common::getRequestVar('mailType', ''); $mail['username'] = Common::unsanitizeInputValue(Common::getRequestVar('mailUsername', '')); $mail['password'] = Common::unsanitizeInputValue(Common::getRequestVar('mailPassword', '')); $mail['encryption'] = Common::getRequestVar('mailEncryption', ''); Config::getInstance()->mail = $mail; }