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)) { Config::getInstance()->database['tables_prefix'] = self::$fixture->tablesPrefix; } Db::query("USE " . $dbName); $installedFixture = \Piwik\Option::get('benchmark_fixture_name'); } catch (Exception $ex) { // ignore } $createEmptyDatabase = $fixtureName != $installedFixture; parent::_setUpBeforeClass($dbName, $createEmptyDatabase); // if we created an empty database, setup the fixture if ($createEmptyDatabase) { self::$fixture->setUp(); \Piwik\Option::set('benchmark_fixture_name', $fixtureName); } }
public function doUpdate(Updater $updater) { // delete schema version_ Option::delete('version_Referers'); $updater->executeMigrations(__FILE__, $this->getMigrations($updater)); // old plugins deleted in 2.0-a17 update file }
/** * @depends testMarkComponentSuccessfullyUpdated_ShouldCreateAnOptionEntry */ public function testMarkComponentSuccessfullyUninstalled_ShouldCreateAnOptionEntry() { $updater = $this->createUpdater(); $updater->markComponentSuccessfullyUninstalled('test_entry'); $value = Option::get('version_test_entry'); $this->assertFalse($value); }
public function testWebArchiving() { if (self::isMysqli() && self::isTravisCI()) { $this->markTestSkipped('Skipping on Mysqli as it randomly fails.'); } $host = Fixture::getRootUrl(); $token = Fixture::getTokenAuth(); $urlTmp = Option::get('piwikUrl'); Option::set('piwikUrl', $host . 'tests/PHPUnit/proxy/index.php'); $url = $host . 'tests/PHPUnit/proxy/archive.php?token_auth=' . $token; $output = Http::sendHttpRequest($url, 600); // ignore random build issues if (empty($output) || strpos($output, \Piwik\CronArchive::NO_ERROR) === false) { $message = "This test has failed. Because it sometimes randomly fails, we skip the test, and ignore this failure.\n"; $message .= "If you see this message often, or in every build, please investigate as this should only be a random and rare occurence!\n"; $message .= "\n\narchive web failed: " . $output . "\n\nurl used: {$url}"; $this->markTestSkipped($message); } if (!empty($urlTmp)) { Option::set('piwikUrl', $urlTmp); } else { Option::delete('piwikUrl'); } $this->assertContains('Starting Piwik reports archiving...', $output); $this->assertContains('Archived website id = 1', $output); $this->assertContains('Done archiving!', $output); $this->compareArchivePhpOutputAgainstExpected($output); }
public function test_rememberToInvalidateArchivedReportsLater_shouldNotCreateEntryTwice() { $this->rememberReport(2, '2014-04-05'); $this->rememberReport(2, '2014-04-05'); $this->rememberReport(2, '2014-04-05'); $this->assertCount(1, Option::getLike('report_to_invalidate%')); }
/** * Tracker requests will automatically trigger the Scheduled tasks. * This is useful for users who don't setup the cron, * but still want daily/weekly/monthly PDF reports emailed automatically. * * This is similar to calling the API CoreAdminHome.runScheduledTasks */ public function runScheduledTasks() { $now = time(); // Currently, there are no hourly tasks. When there are some, // this could be too aggressive minimum interval (some hours would be skipped in case of low traffic) $minimumInterval = TrackerConfig::getConfigValue('scheduled_tasks_min_interval'); // If the user disabled browser archiving, he has already setup a cron // To avoid parallel requests triggering the Scheduled Tasks, // Get last time tasks started executing $cache = Cache::getCacheGeneral(); if ($minimumInterval <= 0 || empty($cache['isBrowserTriggerEnabled'])) { Common::printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled."); return; } $nextRunTime = $cache['lastTrackerCronRun'] + $minimumInterval; if (defined('DEBUG_FORCE_SCHEDULED_TASKS') && DEBUG_FORCE_SCHEDULED_TASKS || $cache['lastTrackerCronRun'] === false || $nextRunTime < $now) { $cache['lastTrackerCronRun'] = $now; Cache::setCacheGeneral($cache); Option::set('lastTrackerCronRun', $cache['lastTrackerCronRun']); Common::printDebug('-> Scheduled Tasks: Starting...'); $invokeScheduledTasksUrl = "?module=API&format=csv&convertToUnicode=0&method=CoreAdminHome.runScheduledTasks&trigger=archivephp"; $cliMulti = new CliMulti(); $cliMulti->runAsSuperUser(); $responses = $cliMulti->request(array($invokeScheduledTasksUrl)); $resultTasks = reset($responses); Common::printDebug($resultTasks); Common::printDebug('Finished Scheduled Tasks.'); } else { Common::printDebug("-> Scheduled tasks not triggered."); } Common::printDebug("Next run will be from: " . date('Y-m-d H:i:s', $nextRunTime) . ' UTC'); }
public function index() { Piwik::checkUserHasSuperUserAccess(); $view = new View('@TasksTimetable/index.twig'); $this->setGeneralVariablesView($view); $tasks = Option::get('TaskScheduler.timetable'); if (!empty($tasks)) { $tasks = unserialize($tasks); } if (empty($tasks)) { $tasks = array(); } else { asort($tasks); } $tsNow = Date::now()->getTimestamp(); $dateFormat = Piwik::translate(Date::DATE_FORMAT_LONG) . ' h:mm:ss'; $formatter = new Formatter(); $tasksFormatted = array(); foreach ($tasks as $name => $timestamp) { $tasksFormatted[] = array('name' => $name, 'executionDate' => Date::factory($timestamp)->getLocalized($dateFormat), 'ts_difference' => $formatter->getPrettyTimeFromSeconds($timestamp - $tsNow)); } $view->currentTime = Date::now()->getLocalized($dateFormat); $view->tasks = $tasksFormatted; return $view->render(); }
/** * Returns version number of a newer Piwik release. * * @return string|bool false if current version is the latest available, * or the latest version number if a newest release is available */ public static function isNewestVersionAvailable() { $latestVersion = Option::get(self::LATEST_VERSION); if (!empty($latestVersion) && version_compare(Version::VERSION, $latestVersion) == -1) { return $latestVersion; } return false; }
public function setUp() { parent::setUp(); $this->manager = new PrivacyManager(); \Piwik\Option::set('delete_logs_enable', 1); \Piwik\Option::set('delete_logs_older_than', 270); \Piwik\Option::set('delete_reports_keep_week_reports', 1); }
/** * Caches the intermediate DataTables used in the getIndividualReportsSummary and * getIndividualMetricsSummary reports in the option table. */ public function cacheDataByArchiveNameReports() { $api = API::getInstance(); $api->getIndividualReportsSummary(true); $api->getIndividualMetricsSummary(true); $now = Date::now()->getLocalized(Date::DATE_FORMAT_SHORT); Option::set(DBStats::TIME_OF_LAST_TASK_RUN_OPTION, $now); }
static function update() { // when updating from pre-3.0 versions, set use_ldap_for_authentication to 0 and make sure // a warning displays in the UI to not set it to 1 \Piwik\Config::getInstance()->LoginLdap['use_ldap_for_authentication'] = 0; \Piwik\Config::getInstance()->forceSave(); Option::set('LoginLdap_updatedFromPre3_0', 1); }
public function setUp() { parent::setUp(); self::updateDatabase(); self::createWebsite("2012-01-01 00:00:00"); $fakeTasks = array('Piwik\\Plugins\\ExamplePlugin\\Tasks.myTask' => Date::factory("2012-01-02 02:33:45")->getTimestampUTC(), 'Piwik\\Plugins\\CoreUpdater\\Tasks.sendNotificationIfUpdateAvailable' => Date::factory("2012-03-04 13:45:56")->getTimestampUTC(), 'Piwik\\Plugins\\CorePluginsAdmin\\Tasks.sendNotificationIfUpdatesAvailable' => Date::factory("2012-02-12 15:12:10")->getTimestampUTC()); Option::set('TaskScheduler.timetable', serialize($fakeTasks)); }
/** * Caches the intermediate DataTables used in the getIndividualReportsSummary and * getIndividualMetricsSummary reports in the option table. */ public function cacheDataByArchiveNameReports() { $api = API::getInstance(); $api->getIndividualReportsSummary(true); $api->getIndividualMetricsSummary(true); $now = Date::now()->getLocalized("%longYear%, %shortMonth% %day%"); Option::set(DBStats::TIME_OF_LAST_TASK_RUN_OPTION, $now); }
/** * @param string $componentPrefix eg 'version_log_visit.' * @return array An array of column names that are marked as installed. eg array('idvist', 'server_time', ...) */ private static function getMarkedAsInstalledColumns($componentPrefix) { $installedVisitColumns = Option::getLike($componentPrefix . '%'); $installedVisitColumns = array_keys($installedVisitColumns); $installedVisitColumns = array_map(function ($entry) use($componentPrefix) { return str_replace($componentPrefix, '', $entry); }, $installedVisitColumns); return $installedVisitColumns; }
public function test_UpdateCommand_DoesNotExecuteUpdate_IfPiwikUpToDate() { Option::set('version_core', Version::VERSION); $result = $this->applicationTester->run(array('command' => 'core:update', '--yes' => true)); $this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage()); // check no update occurred $this->assertContains("Everything is already up to date.", $this->applicationTester->getDisplay()); $this->assertEquals(Version::VERSION, Option::get('version_core')); }
public function test_construct_CorrectlyConvertsOldListValues() { $oldItems = array('2015_01' => array(1, 2, 3), '2013_02' => array(3), 3 => '2015_03', '2014_01' => array(), 4 => '2015_06'); Option::set(ArchivesToPurgeDistributedList::OPTION_INVALIDATED_DATES_SITES_TO_PURGE, serialize($oldItems)); $list = new ArchivesToPurgeDistributedList(); $items = $list->getAll(); $expected = array('2015_03', '2015_06', '2015_01', '2013_02', '2014_01'); $this->assertEquals($expected, array_values($items)); }
public function getAllSiteIdsToArchive() { Option::clearCachedOption('SharedSiteIdsToArchive'); $siteIdsToArchive = Option::get('SharedSiteIdsToArchive'); if (empty($siteIdsToArchive)) { return array(); } return explode(',', trim($siteIdsToArchive)); }
private function migratePluginEmailUpdateSetting() { $isEnabled = Option::get('enableUpdateCommunicationPlugins'); Access::doAsSuperUser(function () use($isEnabled) { $settings = StaticContainer::get('Piwik\\Plugins\\CoreUpdater\\SystemSettings'); $settings->sendPluginUpdateEmail->setValue(!empty($isEnabled)); $settings->save(); }); }
private function set($name, $value, $config) { if ('boolean' == $config['type']) { $value = $value ? '1' : '0'; } else { settype($value, $config['type']); } Option::set($this->prefix($name), $value); Cache::clearCacheGeneral(); }
/** * Update the social definitions * * @see https://github.com/piwik/searchengine-and-social-list */ public function updateSocials() { $url = 'https://raw.githubusercontent.com/piwik/searchengine-and-social-list/master/Socials.yml'; $list = Http::sendHttpRequest($url, 30); $socials = Social::getInstance()->loadYmlData($list); if (count($socials) < 50) { return; } Option::set(Social::OPTION_STORAGE_NAME, base64_encode(serialize($socials))); }
public function test_getAll_ReturnsValueInOption_IfOptionCacheHasSeparateValue() { // get option so cache is loaded Option::get(self::TEST_OPTION_NAME); // set option value to something else $newList = array('1', '2', '3'); $this->initOptionValue($newList); // test option is now different $list = $this->distributedList->getAll(); $this->assertEquals($newList, $list); }
private static function updateIPAnonymizationSettings() { $optionName = 'PrivacyManager.ipAnonymizerEnabled'; $value = Option::get($optionName); if ($value !== false) { // If the config is defined, nothing to do return; } // We disable IP anonymization if it wasn't configured (because by default it has gone from disabled to enabled) Option::set($optionName, '0'); }
public function setUp() { foreach ($this->fixtures as $fixture) { $fixture->setUp(); } 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)); }
/** * @test */ public function should_load_spammer_list_from_options_if_exists() { // We store google.com in the spammer blacklist $list = serialize(array('google.com')); Option::set(ReferrerSpamFilter::OPTION_STORAGE_NAME, $list); $request = new Request(array('urlref' => 'semalt.com')); $this->assertFalse($this->filter->isSpam($request)); // Now Google is blacklisted $request = new Request(array('urlref' => 'google.com')); $this->assertTrue($this->filter->isSpam($request)); Option::delete(ReferrerSpamFilter::OPTION_STORAGE_NAME); }
public function test_getViewDataTableParameters_removesNonOverridableParameter() { $params = array('flat' => '0', 'filters' => 'this is not overridable param and should fail', 'viewDataTable' => 'tableAllColumns'); // 'filters' was removed $paramsExpectedWhenFetched = array('flat' => '0', 'viewDataTable' => 'tableAllColumns'); $login = '******'; $controllerAction = 'API.get'; // simulate an invalid list of parameters (contains 'filters') $paramsKey = sprintf('viewDataTableParameters_%s_%s', $login, $controllerAction); Option::set($paramsKey, json_encode($params)); // check the invalid list is fetched without the overridable parameter $processed = ViewDataTableManager::getViewDataTableParameters($login, $controllerAction); $this->assertEquals($paramsExpectedWhenFetched, $processed); }
public function doUpdate(Updater $updater) { // delete schema version_ Option::delete('version_Referers'); $updater->executeMigrationQueries(__FILE__, $this->getMigrationQueries($updater)); // old plugins deleted in 2.0-a17 update file try { \Piwik\Plugin\Manager::getInstance()->activatePlugin('Referrers'); } catch (\Exception $e) { } try { \Piwik\Plugin\Manager::getInstance()->activatePlugin('ScheduledReports'); } catch (\Exception $e) { } }
public static function update() { // delete schema version_ Option::delete('version_Referers'); Updater::updateDatabase(__FILE__, self::getSql()); // old plugins deleted in 2.0-a17 update file try { \Piwik\Plugin\Manager::getInstance()->activatePlugin('Referrers'); } catch (\Exception $e) { } try { \Piwik\Plugin\Manager::getInstance()->activatePlugin('ScheduledReports'); } catch (\Exception $e) { } }
public function performSetUp($setupEnvironmentOnly = false) { parent::performSetUp($setupEnvironmentOnly); $this->createSegments(); $this->setupDashboards(); $visitorIdDeterministic = bin2hex(Db::fetchOne("SELECT idvisitor FROM " . Common::prefixTable('log_visit') . " WHERE idsite = 2 AND location_latitude IS NOT NULL LIMIT 1")); $this->testEnvironment->forcedIdVisitor = $visitorIdDeterministic; $this->testEnvironment->overlayUrl = $this->getLocalTestSiteUrl(); $this->createOverlayTestSite(); $forcedNowTimestamp = Option::get("Tests.forcedNowTimestamp"); if ($forcedNowTimestamp == false) { throw new Exception("Incorrect fixture setup, Tests.forcedNowTimestamp option does not exist! Run the setup again."); } $this->testEnvironment->forcedNowTimestamp = $forcedNowTimestamp; $this->testEnvironment->save(); }
private function loadSpammerList() { if ($this->spammerList !== null) { return $this->spammerList; } // Read first from the auto-updated list in database $list = Option::get(self::OPTION_STORAGE_NAME); if ($list) { $this->spammerList = unserialize($list); } else { // Fallback to reading the bundled list $file = PIWIK_VENDOR_PATH . '/piwik/referrer-spam-blacklist/spammers.txt'; $this->spammerList = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } return $this->spammerList; }
/** * Retrieve the current version of a recorded component * @param string $name * @return false|string * @throws \Exception */ public static function getCurrentRecordedComponentVersion($name) { try { $currentVersion = Option::get(self::getNameInOptionTable($name)); } catch (\Exception $e) { // mysql error 1146: table doesn't exist if (Db::get()->isErrNo($e, '1146')) { // case when the option table is not yet created (before 0.2.10) $currentVersion = false; } else { // failed for some other reason throw $e; } } return $currentVersion; }