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.')); }
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(); 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(); }
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))); }
/** * Sets the provider to use when tracking. * * @param string $providerId The ID of the provider to use. * @return \Piwik\Plugins\UserCountry\LocationProvider The new current provider. * @throws Exception If the provider ID is invalid. */ public static function setCurrentProvider($providerId) { $provider = self::getProviderById($providerId); if (empty($provider)) { throw new Exception("Invalid provider ID '{$providerId}'. The provider either does not exist or is not available"); } Option::set(self::CURRENT_PROVIDER_OPTION_NAME, $providerId); Cache::clearCacheGeneral(); return $provider; }
public function testGetMaxCustomVariables_ShouldDetectCorrectNumberOfVariables() { Cache::clearCacheGeneral(); $this->assertSame(5, CustomVariables::getMaxCustomVariables()); }
public static function setBrowserTriggerArchiving($enabled) { if (!is_bool($enabled)) { throw new Exception('Browser trigger archiving must be set to true or false.'); } Option::set(self::OPTION_BROWSER_TRIGGER_ARCHIVING, (int) $enabled, $autoLoad = true); Cache::clearCacheGeneral(); }
/** * Updates an existing Custom Dimension. This method updates all values, you need to pass existing values of the * dimension if you do not want to reset any value. Requires at least Admin access for the specified website. * * @param int $idDimension The id of a Custom Dimension. * @param int $idSite The idSite the dimension belongs to * @param string $name The name of the dimension * @param int $active '0' if dimension should be inactive, '1' if dimension should be active * @param array $extractions Either an empty array or if extractions shall be used one or multiple extractions * the format array(array('dimension' => 'url', 'pattern' => 'index_(.+).html'), array('dimension' => 'urlparam', 'pattern' => '...')) * Supported dimensions are eg 'url', 'urlparam' and 'action_name'. To get an up to date list of * supported dimensions request the API method `CustomDimensions.getAvailableExtractionDimensions`. * Note: Extractions can be only set for dimensions in scope 'action'. * @param int|bool|null $caseSensitive '0' if extractions should be applied case insensitive, '1' if extractions should be applied case sensitive, null to keep case sensitive unchanged * @return int Returns the ID of the configured dimension. Note that the same idDimension will be used for different websites. * @throws \Exception */ public function configureExistingCustomDimension($idDimension, $idSite, $name, $active, $extractions = array(), $caseSensitive = null) { Piwik::checkUserHasAdminAccess($idSite); $dimension = new Dimension($idDimension, $idSite); $dimension->checkExists(); if (!isset($caseSensitive)) { $caseSensitive = $dimension->getCaseSensitive(); } $this->checkCustomDimensionConfig($name, $active, $extractions, $caseSensitive); $this->checkExtractionsAreSupportedForScope($dimension->getScope(), $extractions); $this->getConfiguration()->configureExistingDimension($idDimension, $idSite, $name, $active, $extractions, $caseSensitive); Cache::deleteCacheWebsiteAttributes($idSite); Cache::clearCacheGeneral(); }
public static function getSegmentsMetadata($idSite) { // Refresh cache for CustomVariables\Model Cache::clearCacheGeneral(); \Piwik\Plugins\CustomVariables\Model::install(); // Segment matching NONE $segments = \Piwik\Plugins\API\API::getInstance()->getSegmentsMetadata($idSite); return $segments; }
private function postUpdateWebsite($idSite) { Site::clearCache(); Cache::regenerateCacheWebsiteAttributes($idSite); Cache::clearCacheGeneral(); SiteUrls::clearSitesCache(); }
public function test_shouldCacheInstalledIndexes() { Cache::clearCacheGeneral(); $cache = Cache::getCacheGeneral(); $test = array(CustomDimensions::SCOPE_VISIT => range(1, 5), CustomDimensions::SCOPE_ACTION => range(1, 5), CustomDimensions::SCOPE_CONVERSION => range(2, 5)); foreach (CustomDimensions::getScopes() as $scope) { $key = 'custom_dimension_indexes_installed_' . $scope; $this->assertArrayHasKey($key, $cache); $this->assertSame(range(1, 5), $cache[$key]); } }
/** * Activates DoNotTrack header checking. This function will not be called by the Tracker. */ public static function activate() { Option::set(self::OPTION_NAME, 1); Cache::clearCacheGeneral(); }
public static function getSegmentsMetadata() { // Refresh cache for CustomVariables\Model Cache::clearCacheGeneral(); $segments = array(); $environment = new Environment(null); $exception = null; try { $environment->init(); $environment->getContainer()->get('Piwik\\Plugin\\Manager')->loadActivatedPlugins(); foreach (Dimension::getAllDimensions() as $dimension) { if ($dimension instanceof CustomVariableName || $dimension instanceof CustomVariableValue) { continue; // added manually below } foreach ($dimension->getSegments() as $segment) { $segments[] = $segment->getSegment(); } } // add CustomVariables manually since the data provider may not have access to the DB for ($i = 1; $i != Model::DEFAULT_CUSTOM_VAR_COUNT + 1; ++$i) { $segments = array_merge($segments, self::getCustomVariableSegments($i)); } $segments = array_merge($segments, self::getCustomVariableSegments()); } catch (\Exception $ex) { $exception = $ex; echo $ex->getMessage() . "\n" . $ex->getTraceAsString() . "\n"; } $environment->destroy(); if (!empty($exception)) { throw $exception; } return $segments; }
public function uninstall() { $this->configuration->uninstall(); foreach (self::getScopes() as $scope) { $tracking = new Dao\LogTable($scope); $tracking->uninstall(); } Cache::clearCacheGeneral(); $this->isInstalled = false; }
private function clearCache() { Cache::clearCacheGeneral(); }
public function tearDown() { // clean up your test here if needed Cache::clearCacheGeneral(); parent::tearDown(); }