public function test_getCustomDimensionsHavingIndex_shouldOnlyDeleteConfigsForThisSite()
 {
     $this->createManyCustomDimensionCases();
     $index = 1;
     $dimensions = $this->config->getCustomDimensionsHavingIndex('visit', $index);
     $this->assertCount(2, $dimensions);
     $dimensions = $this->config->getCustomDimensionsHavingIndex('action', $index);
     $this->assertCount(2, $dimensions);
     $this->config->deleteConfigurationsForIndex($index);
     // verify deleted
     $dimensions = $this->config->getCustomDimensionsHavingIndex('visit', $index);
     $this->assertSame(array(), $dimensions);
     $dimensions = $this->config->getCustomDimensionsHavingIndex('action', $index);
     $this->assertSame(array(), $dimensions);
     // verify entries for other site still exist
     $dimensions = $this->config->getCustomDimensionsHavingIndex('visit', $index = 2);
     $this->assertCount(2, $dimensions);
 }
 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)));
 }