/** * Called on Core install, update, plugin enable/disable * Will clear all cache that could be affected by the change in configuration being made */ public static function deleteAllCacheOnUpdate($pluginName = false) { AssetManager::getInstance()->removeMergedAssets($pluginName); View::clearCompiledTemplates(); Cache::deleteTrackerCache(); self::clearPhpCaches(); }
public function testGetMaxCustomVariables_ShouldReadFromCacheIfPossible() { $cache = Cache::getCacheGeneral(); $cache['CustomVariables.MaxNumCustomVariables'] = 10; Cache::setCacheGeneral($cache); $this->assertSame(10, CustomVariables::getMaxCustomVariables()); }
protected function execute(InputInterface $input, OutputInterface $output) { $numVarsToSet = $this->getNumVariablesToSet($input); $numChangesToPerform = $this->getNumberOfChangesToPerform($numVarsToSet); if (0 === $numChangesToPerform) { $this->writeSuccessMessage($output, array('Your Piwik is already configured for ' . $numVarsToSet . ' custom variables.')); return; } $output->writeln(''); $output->writeln(sprintf('Configuring Piwik for %d custom variables', $numVarsToSet)); foreach (Model::getScopes() as $scope) { $this->printChanges($scope, $numVarsToSet, $output); } if (!$this->confirmChange($output)) { return; } $output->writeln(''); $output->writeln('Starting to apply changes'); $output->writeln(''); $this->progress = $this->initProgress($numChangesToPerform, $output); foreach (Model::getScopes() as $scope) { $this->performChange($scope, $numVarsToSet, $output); } Cache::clearCacheGeneral(); $this->progress->finish(); $this->writeSuccessMessage($output, array('Your Piwik is now configured for ' . $numVarsToSet . ' custom variables.')); }
public function onSiteDeleted($idSite) { // we do not delete logs here on purpose (you can run these queries on the log_ tables to delete all data) Cache::deleteCacheWebsiteAttributes($idSite); $archiveInvalidator = new ArchiveInvalidator(); $archiveInvalidator->forgetRememberedArchivedReportsToInvalidateForSite($idSite); }
static function update($schema = 'Myisam') { // force regeneration of cache files following #648 Piwik::setUserIsSuperUser(); $allSiteIds = API::getInstance()->getAllSitesId(); Cache::regenerateCacheWebsiteAttributes($allSiteIds); }
/** * 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 onSiteDeleted($idSite) { // we do not delete logs here on purpose (you can run these queries on the log_ tables to delete all data) Cache::deleteCacheWebsiteAttributes($idSite); $archiveInvalidator = StaticContainer::get('Piwik\\Archive\\ArchiveInvalidator'); $archiveInvalidator->forgetRememberedArchivedReportsToInvalidateForSite($idSite); MeasurableSettingsTable::removeAllSettingsForSite($idSite); }
public function setUp() { parent::setUp(); Fixture::createWebsite('2014-01-01 00:00:00'); Fixture::createWebsite('2014-01-01 00:00:00'); Cache::deleteTrackerCache(); $_SERVER['HTTP_USER_AGENT'] = ''; }
public function setUp() { parent::setUp(); Fixture::createWebsite('2014-01-01 00:00:00'); Fixture::createWebsite('2014-01-01 00:00:00'); Cache::deleteTrackerCache(); $this->request = $this->buildRequest(array('idsite' => '1')); }
public static function getGoalDefinitions($idSite) { $websiteAttributes = Cache::getCacheWebsiteAttributes($idSite); if (isset($websiteAttributes['goals'])) { return $websiteAttributes['goals']; } return array(); }
public function onSiteDeleted($idSite) { // we do not delete logs here on purpose (you can run these queries on the log_ tables to delete all data) Cache::deleteCacheWebsiteAttributes($idSite); $archiveInvalidator = StaticContainer::get('Piwik\\Archive\\ArchiveInvalidator'); $archiveInvalidator->forgetRememberedArchivedReportsToInvalidateForSite($idSite); $measurableStorage = new Storage(Db::get(), $idSite); $measurableStorage->deleteAllValues(); }
public function test_storageCreateACacheEntryIfNoCacheExistsYet() { $cache = Cache::getCacheGeneral(); $this->assertArrayNotHasKey('settingsStorage', $cache); // make sure there is no cache entry yet $this->setSettingValueAndMakeSureCacheGetsCreated('myVal'); $cache = $this->getCache()->fetch($this->storage->getOptionKey()); $this->assertEquals(array($this->setting->getKey() => 'myVal'), $cache); }
protected function sendRequest($url, $method = 'GET', $data = null, $force = false) { // if doing a bulk request, store the url if ($this->doBulkRequests && !$force) { $this->storedTrackingActions[] = $url; return true; } if ($method == 'POST') { $requests = array(); foreach ($this->storedTrackingActions as $action) { $requests[] = $this->parseUrl($action); } $testEnvironmentArgs = array(); } else { $testEnvironmentArgs = $this->parseUrl($url); $requests = array($testEnvironmentArgs); } // unset cached values Cache::$trackerCache = null; Tracker::setForceIp(null); Tracker::setForceDateTime(null); // save some values $plugins = Config::getInstance()->Plugins['Plugins']; $oldTrackerConfig = Config::getInstance()->Tracker; \Piwik\Plugin\Manager::getInstance()->unloadPlugins(); // modify config $GLOBALS['PIWIK_TRACKER_MODE'] = true; $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = true; Tracker::$initTrackerMode = false; Tracker::setTestEnvironment($testEnvironmentArgs, $method); // set language $oldLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''; $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $this->acceptLanguage; // set user agent $oldUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $_SERVER['HTTP_USER_AGENT'] = $this->userAgent; // set cookie $oldCookie = $_COOKIE; // parse_str(parse_url($this->requestCookie, PHP_URL_QUERY), $_COOKIE); // do tracking and capture output ob_start(); $localTracker = new Tracker(); $localTracker->main($requests); $output = ob_get_contents(); ob_end_clean(); // restore vars Config::getInstance()->Tracker = $oldTrackerConfig; $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $oldLang; $_SERVER['HTTP_USER_AGENT'] = $oldUserAgent; $_COOKIE = $oldCookie; $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = false; $GLOBALS['PIWIK_TRACKER_MODE'] = false; unset($_GET['bots']); // reload plugins \Piwik\Plugin\Manager::getInstance()->loadPlugins($plugins); return $output; }
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(); }
public function setUp() { parent::setUp(); Fixture::createWebsite('2014-01-01 00:00:00'); Tracker\Cache::deleteTrackerCache(); $this->response = new Response(); $this->handler = new Handler(); $this->handler->setResponse($this->response); $this->tracker = new Tracker(); $this->requestSet = new RequestSet(); }
public function setUp() { parent::setUp(); Fixture::createWebsite('2014-01-01 00:00:00'); Fixture::createSuperUser(); Tracker\Cache::deleteTrackerCache(); $this->backend = $this->createRedisBackend(); $this->queue = Queue\Factory::makeQueueManager($this->backend); $this->response = new Response(); $this->handler = new Handler(); $this->handler->setResponse($this->response); $this->tracker = new Tracker(); $this->requestSet = new RequestSet(); }
public function setUp() { parent::setUp(); if (!Fixture::siteCreated(1)) { Fixture::createWebsite('2012-01-01 00:00:00'); } if (!Fixture::siteCreated(2)) { Fixture::createWebsite('2012-01-01 00:00:00'); } Cache::clearCacheGeneral(); Cache::deleteCacheWebsiteAttributes($idSite = 1); Cache::deleteCacheWebsiteAttributes($idSite = 2); $this->processor = new Processor(); }
private function configureSomeDimensions() { $configuration = new Configuration(); $configuration->configureNewDimension($this->idSite, 'MyName1', CustomDimensions::SCOPE_VISIT, 1, $active = true, $extractions = array(), $caseSensitive = true); $configuration->configureNewDimension($this->idSite, 'MyName2', CustomDimensions::SCOPE_VISIT, 2, $active = true, $extractions = array(), $caseSensitive = true); $configuration->configureNewDimension($this->idSite2, 'MyName1', CustomDimensions::SCOPE_VISIT, 1, $active = true, $extractions = array(), $caseSensitive = true); $extraction1 = new Extraction('urlparam', 'test'); $extraction2 = new Extraction('urlparam', 'param'); $extraction3 = new Extraction('url', '/sub_(.{2})/page'); $configuration->configureNewDimension($this->idSite, 'MyName3', CustomDimensions::SCOPE_ACTION, 1, $active = true, $extractions = array($extraction3->toArray()), $caseSensitive = true); $configuration->configureNewDimension($this->idSite, 'MyName4', CustomDimensions::SCOPE_ACTION, 2, $active = false, $extractions = array(), $caseSensitive = true); $configuration->configureNewDimension($this->idSite, 'MyName5', CustomDimensions::SCOPE_ACTION, 3, $active = true, $extractions = array($extraction1->toArray(), $extraction2->toArray()), $caseSensitive = true); $configuration->configureNewDimension($this->idSite, 'MyName6', CustomDimensions::SCOPE_VISIT, 4, $active = true, $extractions = array(), $caseSensitive = true); Cache::deleteCacheWebsiteAttributes(1); Cache::deleteCacheWebsiteAttributes(2); Cache::clearCacheGeneral(); }
public static function getMaxCustomVariables() { $cache = Cache::getCacheGeneral(); $cacheKey = 'CustomVariables.MaxNumCustomVariables'; if (!array_key_exists($cacheKey, $cache)) { $maxCustomVar = 0; foreach (Model::getScopes() as $scope) { $model = new Model($scope); $highestIndex = $model->getHighestCustomVarIndex(); if ($highestIndex > $maxCustomVar) { $maxCustomVar = $highestIndex; } } $cache[$cacheKey] = $maxCustomVar; Cache::setCacheGeneral($cache); } return $cache[$cacheKey]; }
static function update() { $obsoleteFiles = array(PIWIK_INCLUDE_PATH . '/core/Db/Mysqli.php'); foreach ($obsoleteFiles as $obsoleteFile) { if (file_exists($obsoleteFile)) { @unlink($obsoleteFile); } } $obsoleteDirectories = array(PIWIK_INCLUDE_PATH . '/core/Db/Pdo'); foreach ($obsoleteDirectories as $dir) { if (file_exists($dir)) { Filesystem::unlinkRecursive($dir, true); } } // force regeneration of cache files Piwik::setUserHasSuperUserAccess(); $allSiteIds = API::getInstance()->getAllSitesId(); Cache::regenerateCacheWebsiteAttributes($allSiteIds); }
protected function execute(InputInterface $input, OutputInterface $output) { $scope = $this->getScope($input); $tracking = new LogTable($scope); $installedIndexes = $tracking->getInstalledIndexes(); $index = $this->getIndex($input, $installedIndexes); $output->writeln(sprintf('Remove Custom Dimension at index %d in scope %s.', $index, $scope)); $configuration = new Configuration(); $configs = $configuration->getCustomDimensionsHavingIndex($scope, $index); $names = array(); foreach ($configs as $config) { $names[] = $config['name']; } if (empty($names)) { $output->writeln('This index is currently not used by any website'); } else { $output->writeln(sprintf('This index is used by %d websites and used for the following Custom Dimensions: "%s"', count($names), implode('", "', $names))); } $output->writeln(''); $output->writeln('<comment>This causes schema changes in the database and may take a very long time.</comment>'); $output->writeln('<comment>Removing tracked Custom Dimension data cannot be undone unless you have a backup.</comment>'); $noInteraction = $input->getOption('no-interaction'); if (!$noInteraction && !$this->confirmChange($output)) { return; } $output->writeln(''); $output->writeln('Starting to remove this Custom Dimension.'); $output->writeln(''); $tracking = new LogTable($scope); $tracking->removeCustomDimension($index); $configuration->deleteConfigurationsForIndex($index); if ($scope === CustomDimensions::SCOPE_VISIT) { $tracking = new LogTable(CustomDimensions::SCOPE_CONVERSION); $tracking->removeCustomDimension($index); } Cache::clearCacheGeneral(); $numDimensionsAvailable = $tracking->getNumInstalledIndexes(); $this->writeSuccessMessage($output, array(sprintf('Your Piwik is now configured for up to %d Custom Dimensions in scope %s.', $numDimensionsAvailable, $scope))); }
protected function execute(InputInterface $input, OutputInterface $output) { $scope = $this->getScope($input); $count = $this->getCount($input); $output->writeln(sprintf('Adding %d Custom Dimension(s) in scope %s.', $count, $scope)); $output->writeln('<info>This causes schema changes in the database and may take a very long time.</info>'); $noInteraction = $input->getOption('no-interaction'); if (!$noInteraction && !$this->confirmChange($output)) { return; } $output->writeln(''); $output->writeln('Starting to add Custom Dimension(s)'); $output->writeln(''); $tracking = new LogTable($scope); $tracking->addManyCustomDimensions($count); if ($scope === CustomDimensions::SCOPE_VISIT) { $tracking = new LogTable(CustomDimensions::SCOPE_CONVERSION); $tracking->addManyCustomDimensions($count); } Cache::clearCacheGeneral(); $numDimensionsAvailable = $tracking->getNumInstalledIndexes(); $this->writeSuccessMessage($output, array(sprintf('Your Piwik is now configured for up to %d Custom Dimensions in scope %s.', $numDimensionsAvailable, $scope))); }
/** * Returns the number of available custom variables that can be used. * * "Can be used" is identifed by the minimum number of available custom variables across all relevant tables. Eg * if there are 6 custom variables installed in log_visit but only 5 in log_conversion, we consider only 5 custom * variables as usable. * @return int */ public static function getNumUsableCustomVariables() { $cache = Cache::getCacheGeneral(); $cacheKey = 'CustomVariables.NumUsableCustomVariables'; if (!array_key_exists($cacheKey, $cache)) { $minCustomVar = null; foreach (Model::getScopes() as $scope) { $model = new Model($scope); $highestIndex = $model->getHighestCustomVarIndex(); if (!isset($minCustomVar)) { $minCustomVar = $highestIndex; } if ($highestIndex < $minCustomVar) { $minCustomVar = $highestIndex; } } if (!isset($minCustomVar)) { $minCustomVar = 0; } $cache[$cacheKey] = $minCustomVar; Cache::setCacheGeneral($cache); } return $cache[$cacheKey]; }
private function clearCache() { Cache::clearCacheGeneral(); }
/** * 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 */ protected static 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 = Config::getInstance()->Tracker['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 (isset($GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS']) && $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] || $cache['lastTrackerCronRun'] === false || $nextRunTime < $now) { $cache['lastTrackerCronRun'] = $now; Cache::setCacheGeneral($cache); self::initCorePiwikInTrackerMode(); Option::set('lastTrackerCronRun', $cache['lastTrackerCronRun']); Common::printDebug('-> Scheduled Tasks: Starting...'); // save current user privilege and temporarily assume Super User privilege $isSuperUser = Piwik::hasUserSuperUserAccess(); // Scheduled tasks assume Super User is running Piwik::setUserHasSuperUserAccess(); // While each plugins should ensure that necessary languages are loaded, // we ensure English translations at least are loaded Translate::loadEnglishTranslation(); ob_start(); CronArchive::$url = SettingsPiwik::getPiwikUrl(); $cronArchive = new CronArchive(); $cronArchive->runScheduledTasksInTrackerMode(); $resultTasks = ob_get_contents(); ob_clean(); // restore original user privilege Piwik::setUserHasSuperUserAccess($isSuperUser); foreach (explode('</pre>', $resultTasks) as $resultTask) { Common::printDebug(str_replace('<pre>', '', $resultTask)); } 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'); }
/** * Returns the ID of the current LocationProvider (see UserCountry plugin code) from * the Tracker cache. */ public static function getCurrentLocationProviderId() { $cache = TrackerCache::getCacheGeneral(); return empty($cache['currentLocationProviderId']) ? DefaultProvider::ID : $cache['currentLocationProviderId']; }
public function getCachedInstalledIndexesForScope($scope) { $cache = Cache::getCacheGeneral(); $key = 'custom_dimension_indexes_installed_' . $scope; if (empty($cache[$key])) { return array(); } return $cache[$key]; }
/** * We have previously tried to detect the campaign variables in the URL * so at this stage, if the referrer host is the current host, * or if the referrer host is any of the registered URL for this website, * it is considered a direct entry * @return bool */ protected function detectReferrerDirectEntry() { if (empty($this->referrerHost)) { return false; } $urlsByHost = $this->getCachedUrlsByHostAndIdSite(); $directEntry = new SiteUrls(); $matchingSites = $directEntry->getIdSitesMatchingUrl($this->referrerUrlParse, $urlsByHost); if (isset($matchingSites) && is_array($matchingSites) && in_array($this->idsite, $matchingSites)) { $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY; return true; } elseif (isset($matchingSites)) { return false; } $site = Cache::getCacheWebsiteAttributes($this->idsite); $excludeUnknowns = $site['exclude_unknown_urls']; // fallback logic if the referrer domain is not known to any site to not break BC if (!$excludeUnknowns && isset($this->currentUrlParse['host'])) { // this might be actually buggy if first thing tracked is eg an outlink and referrer is from that site $currentHost = Common::mb_strtolower($this->currentUrlParse['host']); if ($currentHost == Common::mb_strtolower($this->referrerHost)) { $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY; return true; } } return false; }
/** * Returns true if the specified user agent should be excluded for the current site or not. * * Visits whose user agent string contains one of the excluded_user_agents strings for the * site being tracked (or one of the global strings) will be excluded. * * @internal param string $this ->userAgent The user agent string. * @return bool */ protected function isUserAgentExcluded() { $websiteAttributes = Cache::getCacheWebsiteAttributes($this->idSite); if (!empty($websiteAttributes['excluded_user_agents'])) { foreach ($websiteAttributes['excluded_user_agents'] as $excludedUserAgent) { // if the excluded user agent string part is in this visit's user agent, this visit should be excluded if (stripos($this->userAgent, $excludedUserAgent) !== false) { return true; } } } return false; }
/** * Sets list of URL query parameters to be excluded on all websites. * Will also apply to websites created in the future. * * @param string $excludedQueryParameters Comma separated list of URL query parameters to exclude from URLs * @return bool */ public function setGlobalExcludedQueryParameters($excludedQueryParameters) { Piwik::checkUserHasSuperUserAccess(); $excludedQueryParameters = $this->checkAndReturnCommaSeparatedStringList($excludedQueryParameters); Option::set(self::OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL, $excludedQueryParameters); Cache::deleteTrackerCache(); return true; }