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_uninstall_shouldRemoveAllColumnsFromLogTablesAndUninstallConfigTable() { $this->plugin->uninstall(); foreach (CustomDimensions::getScopes() as $scope) { $logTable = new LogTable($scope); $this->assertSame(array(), $logTable->getInstalledIndexes()); } try { $this->configureSomeDimensions(); } catch (\Exception $e) { // should fail as table was removed } $this->plugin->install(); }
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 setTrackerCacheGeneral(&$cacheContent) { foreach (self::getScopes() as $scope) { $tracking = new LogTable($scope); $cacheContent['custom_dimension_indexes_installed_' . $scope] = $tracking->getInstalledIndexes(); } }
public function testExecute_ShouldAddSpecifiedCount_IfScopeIsVisitShouldAlsoUpdateConversion() { $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT); $this->assertSame(range(1, 5), $logVisit->getInstalledIndexes()); $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION); $this->assertSame(range(1, 5), $logConversion->getInstalledIndexes()); $result = $this->executeCommand(CustomDimensions::SCOPE_VISIT, $index = 2); $this->assertContains('Remove Custom Dimension at index 2 in scope visit', $result); $this->assertContains('Are you sure you want to perform this action?', $result); $this->assertContains('Starting to remove this Custom Dimension', $result); $this->assertContains('Your Piwik is now configured for up to 4 Custom Dimensions in scope visit.', $result); $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT); $this->assertSame(array(1, 3, 4, 5), $logVisit->getInstalledIndexes()); $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION); $this->assertSame(array(1, 3, 4, 5), $logConversion->getInstalledIndexes()); $logAction = new LogTable(CustomDimensions::SCOPE_ACTION); $this->assertSame(array(1, 2, 4, 5), $logAction->getInstalledIndexes()); }