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;
 }
 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]);
     }
 }