Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-04-03 06:48:35 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-04-03 06:48:35 +0400
commitd5e6e8f7b783f41324ec4aee4e13bd0eb159f87f (patch)
treefbebc9a9ada48a94b6329dafb25254a2d83ae8d8 /plugins
parente1387ab1087ae72173dda3803d369baea08fc8f6 (diff)
some tweaks to the command ui output as well as some documentation and tests
Diffstat (limited to 'plugins')
-rw-r--r--plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php27
-rw-r--r--plugins/CustomVariables/Model.php17
-rw-r--r--plugins/CustomVariables/tests/ModelTest.php16
3 files changed, 55 insertions, 5 deletions
diff --git a/plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php b/plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php
index acd7233a1e..b08946eab4 100644
--- a/plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php
+++ b/plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php
@@ -27,13 +27,13 @@ class SetNumberOfCustomVariables extends ConsoleCommand
protected function configure()
{
- $this->setName('customvariables:set-number-available-custom-variables');
+ $this->setName('customvariables:set-max-custom-variables');
$this->setDescription('Change the number of available custom variables');
$this->setHelp("Example:
-./console customvariables:set-number-available-custom-variables 10
+./console customvariables:set-max-custom-variables 10
=> 10 custom variables will be available in total
");
- $this->addArgument('maxCustomVars', InputArgument::REQUIRED, 'The number of available custom variables');
+ $this->addArgument('maxCustomVars', InputArgument::REQUIRED, 'Set the number of max available custom variables');
}
protected function execute(InputInterface $input, OutputInterface $output)
@@ -48,6 +48,11 @@ class SetNumberOfCustomVariables extends ConsoleCommand
return;
}
+
+ $output->writeln('');
+ $output->writeln(sprintf('Configuring Piwik for %d custom variables', $numVarsToSet));
+
+
foreach (Model::getScopes() as $scope) {
$this->printChanges($scope, $numVarsToSet, $output);
}
@@ -56,16 +61,19 @@ class SetNumberOfCustomVariables extends ConsoleCommand
return;
}
+
$output->writeln('');
$output->writeln('Starting to apply changes');
$output->writeln('');
+
$this->progress = $this->initProgress($numChangesToPerform, $output);
foreach (Model::getScopes() as $scope) {
$this->performChange($scope, $numVarsToSet, $output);
}
+
Cache::clearCacheGeneral();
$this->progress->finish();
@@ -139,14 +147,23 @@ class SetNumberOfCustomVariables extends ConsoleCommand
if ($numVarsToSet > $numCurrentCustomVars) {
- $indexes = implode(',', range($highestIndex + 1, $highestIndex + $numVarsDifference));
+ $indexes = $highestIndex + 1;
+ if (1 !== $numVarsDifference) {
+ $indexes .= ' - ' . ($highestIndex + $numVarsDifference);
+ }
+
$output->writeln(
sprintf('%s new custom variables having the index(es) %s will be ADDED', $numVarsDifference, $indexes)
);
} elseif ($numVarsToSet < $numCurrentCustomVars) {
- $indexes = implode(',', range($highestIndex - $numVarsDifference + 1, $highestIndex));
+ $indexes = $highestIndex - $numVarsDifference + 1;
+
+ if (1 !== $numVarsDifference) {
+ $indexes .= ' - ' . $highestIndex;
+ }
+
$output->writeln(
sprintf("%s existing custom variables having the index(es) %s will be REMOVED.", $numVarsDifference, $indexes)
);
diff --git a/plugins/CustomVariables/Model.php b/plugins/CustomVariables/Model.php
index 252718f87a..60cbeac947 100644
--- a/plugins/CustomVariables/Model.php
+++ b/plugins/CustomVariables/Model.php
@@ -43,6 +43,10 @@ class Model
}
}
+ /**
+ * @see getHighestCustomVarIndex()
+ * @return int
+ */
public function getCurrentNumCustomVars()
{
$customVarColumns = $this->getCustomVarColumnNames();
@@ -52,6 +56,19 @@ class Model
return (int) $currentNumCustomVars;
}
+ /**
+ * result of getHighestCustomVarIndex() can be different to getCurrentNumCustomVars() in case there are some missing
+ * custom variable indexes. For instance in case of manual changes on the DB
+ *
+ * custom_var_v1
+ * custom_var_v2
+ * custom_var_v4
+ *
+ * getHighestCustomVarIndex() -> returns 4
+ * getCurrentNumCustomVars() -> returns 3
+ *
+ * @return int
+ */
public function getHighestCustomVarIndex()
{
$columns = $this->getCustomVarColumnNames();
diff --git a/plugins/CustomVariables/tests/ModelTest.php b/plugins/CustomVariables/tests/ModelTest.php
index 744dae2ce7..1cf77ac152 100644
--- a/plugins/CustomVariables/tests/ModelTest.php
+++ b/plugins/CustomVariables/tests/ModelTest.php
@@ -17,6 +17,22 @@ use Piwik\Plugins\CustomVariables\Model;
*/
class ModelTest extends \DatabaseTestCase
{
+ /**
+ * @expectedException \Exception
+ */
+ public function test_construct_shouldFailInCaseOfEmptyScope()
+ {
+ new Model(null);
+ }
+
+ /**
+ * @expectedException \Exception
+ */
+ public function test_construct_shouldFailInCaseOfInvalidScope()
+ {
+ new Model('inValId');
+ }
+
public function testGetAllScopes()
{
$this->assertEquals(array('log_link_visit_action', 'log_visit', 'log_conversion'), Model::getScopes());