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 test_getNumInstalledIndexes_shouldReturnInstalledIndexes()
 {
     $expected = 5;
     $this->assertSame($expected, $this->logVisit->getNumInstalledIndexes());
     $this->assertSame($expected, $this->logAction->getNumInstalledIndexes());
     $this->assertSame($expected, $this->logConverison->getNumInstalledIndexes());
     $this->logAction->addManyCustomDimensions(1);
     $this->assertSame($expected, $this->logVisit->getNumInstalledIndexes());
     $this->assertSame(6, $this->logAction->getNumInstalledIndexes());
     $this->assertSame($expected, $this->logConverison->getNumInstalledIndexes());
     $this->logVisit->removeCustomDimension(2);
     $this->assertSame(4, $this->logVisit->getNumInstalledIndexes());
     $this->assertSame(6, $this->logAction->getNumInstalledIndexes());
     $this->assertSame($expected, $this->logConverison->getNumInstalledIndexes());
 }
 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)));
 }