public function testExecute_ShouldOutputErrorMessage_IfColumnsDoNotMatch()
    {
        $model = new LogTable(CustomDimensions::SCOPE_CONVERSION);
        $model->removeCustomDimension(5);
        $this->assertContains('We found an error, Custom Dimensions in scope "conversion" are not correctly installed. Execute the following command to repair it:
./console customdimensions:add-custom-dimension --scope=conversion --count=1', $this->executeCommand());
    }
 public function test_getCachedCustomDimensionIndexes()
 {
     $logTable = new LogTable(CustomDimensions::SCOPE_ACTION);
     $logTable->removeCustomDimension(1);
     $indexes = Processor::getCachedCustomDimensionIndexes(CustomDimensions::SCOPE_VISIT);
     $this->assertSame(range(1, 5), $indexes);
     $indexes = Processor::getCachedCustomDimensionIndexes(CustomDimensions::SCOPE_ACTION);
     $this->assertSame(range(2, 5), $indexes);
 }
 public function test_addManyCustomDimensions_shouldAddNewColumns()
 {
     // should add nothing as not a valid index
     $this->logVisit->addManyCustomDimensions(0);
     $this->logVisit->addManyCustomDimensions(null);
     $this->assertSame(range(1, 5), $this->logVisit->getInstalledIndexes());
     $this->logVisit->addManyCustomDimensions(1);
     $this->assertSame(range(1, 6), $this->logVisit->getInstalledIndexes());
     $this->logVisit->addManyCustomDimensions(4);
     $this->assertSame(range(1, 10), $this->logVisit->getInstalledIndexes());
     // should automatically add after highest index if some indexes are missing in between
     $this->logVisit->removeCustomDimension('8');
     $this->logVisit->removeCustomDimension('2');
     $this->logVisit->removeCustomDimension('1');
     $this->logVisit->addManyCustomDimensions(2);
     $this->assertSame(array(3, 4, 5, 6, 7, 9, 10, 11, 12), $this->logVisit->getInstalledIndexes());
 }
 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)));
 }
 public function test_addConversionInformation_shouldIgnoreAnIndexIfTheIndexIsMissingInConversionTable()
 {
     $this->configureSomeDimensions();
     $logTable = new LogTable(CustomDimensions::SCOPE_CONVERSION);
     $logTable->removeCustomDimension(1);
     $conversion = array();
     $request = new Request(array('idsite' => 1));
     $visit = array('custom_dimension_1' => 'value 1', 'custom_dimension_4' => 'value 4');
     $this->plugin->addConversionInformation($conversion, $visit, $request);
     $this->assertSame(array('custom_dimension_4' => 'value 4'), $conversion);
 }