protected function execute(InputInterface $input, OutputInterface $output) { foreach (CustomDimensions::getScopes() as $scope) { $tracking = new LogTable($scope); $output->writeln(sprintf('%s Custom Dimensions available in scope "%s"', $tracking->getNumInstalledIndexes(), $scope)); if ($scope === CustomDimensions::SCOPE_CONVERSION) { $output->writeln(sprintf('Custom Dimensions are automatically added via the scope "%s" and cannot be added manually', CustomDimensions::SCOPE_VISIT)); } else { $output->writeln(sprintf('To add a Custom Dimension execute "<comment>./console customdimensions:add-custom-dimension --scope=%s</comment>"', $scope)); } $output->writeln('Installed indexes are:'); foreach ($tracking->getInstalledIndexes() as $index) { $output->writeln(sprintf('%d to remove this Custom Dimension execute <comment>./console customdimensions:remove-custom-dimension --scope=%s --index=%d</comment>', $index, $scope, $index)); } $output->writeln(''); } $visit = new LogTable(CustomDimensions::SCOPE_VISIT); $numVisit = $visit->getNumInstalledIndexes(); $conversion = new LogTable(CustomDimensions::SCOPE_CONVERSION); $numConversions = $conversion->getNumInstalledIndexes(); if ($numConversions < $numVisit) { $output->writeln(''); $output->writeln('<error>We found an error, Custom Dimensions in scope "conversion" are not correctly installed. Execute the following command to repair it:</error>'); $output->writeln(sprintf('<comment>./console customdimensions:add-custom-dimension --scope=%s --count=%d</comment>', CustomDimensions::SCOPE_CONVERSION, $numVisit - $numConversions)); } }
public function check() { $scopes = CustomDimensions::getScopes(); if (empty($this->scope) || !in_array($this->scope, $scopes, true)) { $scopes = implode(', ', $scopes); $scope = $this->scope; throw new \Exception("Invalid value '{$scope}' for 'scope' specified. Available scopes are: {$scopes}"); } }
private function getScope(InputInterface $input) { $scope = $input->getOption('scope'); if (empty($scope) || !in_array($scope, CustomDimensions::getScopes())) { // we also allow scope "conversion" in case on needs to repair something but we don't document as it would be rather confusing $message = sprintf('The specified scope is invalid. Use either "--scope=%s" or "--scope=%s"', CustomDimensions::SCOPE_VISIT, CustomDimensions::SCOPE_ACTION); throw new \InvalidArgumentException($message); } return $scope; }
/** * @dataProvider getScopesSupportExtractions */ public function test_doesScopeSupportExtractions($expectedSupportsExtractions, $scope) { $this->assertSame($expectedSupportsExtractions, CustomDimensions::doesScopeSupportExtractions($scope)); }
/** * Get a list of all supported scopes that can be used in the API method * `CustomDimensions.configureNewCustomDimension`. The response also contains information whether more Custom * Dimensions can be created or not. Requires at least Admin access for the specified website. * * @param int $idSite * @return array */ public function getAvailableScopes($idSite) { Piwik::checkUserHasAdminAccess($idSite); $scopes = array(); foreach (CustomDimensions::getPublicScopes() as $scope) { $configs = $this->getConfiguration()->getCustomDimensionsHavingScope($idSite, $scope); $indexes = $this->getTracking($scope)->getInstalledIndexes(); $scopes[] = array('value' => $scope, 'name' => Piwik::translate('General_TrackingScope' . ucfirst($scope)), 'numSlotsAvailable' => count($indexes), 'numSlotsUsed' => count($configs), 'numSlotsLeft' => count($indexes) - count($configs), 'supportsExtractions' => CustomDimensions::doesScopeSupportExtractions($scope)); } return $scopes; }