private function setUpCustomVars()
 {
     foreach (Model::getScopes() as $scope) {
         $model = new Model($scope);
         $model->addCustomVariable();
         $model->addCustomVariable();
         $model->addCustomVariable();
     }
 }
Esempio n. 2
0
 private function hasEverywhereSameAmountOfVariables()
 {
     $indexesBefore = null;
     foreach (Model::getScopes() as $scope) {
         $model = new Model($scope);
         $indexes = $model->getCustomVarIndexes();
         if (is_null($indexesBefore)) {
             $indexesBefore = $indexes;
         } elseif ($indexes != $indexesBefore) {
             return false;
         }
     }
     return true;
 }
Esempio n. 3
0
 public static function getMaxCustomVariables()
 {
     $cache = Cache::getCacheGeneral();
     $cacheKey = 'CustomVariables.MaxNumCustomVariables';
     if (!array_key_exists($cacheKey, $cache)) {
         $maxCustomVar = 0;
         foreach (Model::getScopes() as $scope) {
             $model = new Model($scope);
             $highestIndex = $model->getHighestCustomVarIndex();
             if ($highestIndex > $maxCustomVar) {
                 $maxCustomVar = $highestIndex;
             }
         }
         $cache[$cacheKey] = $maxCustomVar;
         Cache::setCacheGeneral($cache);
     }
     return $cache[$cacheKey];
 }
Esempio n. 4
0
 public function testGetCustomVariableIndexFromFieldName()
 {
     $this->assertSame(0, Model::getCustomVariableIndexFromFieldName('custom_var_k0'));
     $this->assertSame(0, Model::getCustomVariableIndexFromFieldName('custom_var_v0'));
     $this->assertSame(5, Model::getCustomVariableIndexFromFieldName('custom_var_k5'));
     $this->assertSame(5, Model::getCustomVariableIndexFromFieldName('custom_var_v5'));
     $this->assertSame(938, Model::getCustomVariableIndexFromFieldName('custom_var_k938'));
     $this->assertSame(938, Model::getCustomVariableIndexFromFieldName('custom_var_v938'));
     $this->assertSame(null, Model::getCustomVariableIndexFromFieldName('otherfield'));
 }
Esempio n. 5
0
 /**
  * Returns the number of available custom variables that can be used.
  *
  * "Can be used" is identifed by the minimum number of available custom variables across all relevant tables. Eg
  * if there are 6 custom variables installed in log_visit but only 5 in log_conversion, we consider only 5 custom
  * variables as usable.
  * @return int
  */
 public static function getNumUsableCustomVariables()
 {
     $cache = Cache::getCacheGeneral();
     $cacheKey = 'CustomVariables.NumUsableCustomVariables';
     if (!array_key_exists($cacheKey, $cache)) {
         $minCustomVar = null;
         foreach (Model::getScopes() as $scope) {
             $model = new Model($scope);
             $highestIndex = $model->getHighestCustomVarIndex();
             if (!isset($minCustomVar)) {
                 $minCustomVar = $highestIndex;
             }
             if ($highestIndex < $minCustomVar) {
                 $minCustomVar = $highestIndex;
             }
         }
         if (!isset($minCustomVar)) {
             $minCustomVar = 0;
         }
         $cache[$cacheKey] = $minCustomVar;
         Cache::setCacheGeneral($cache);
     }
     return $cache[$cacheKey];
 }
Esempio n. 6
0
 public static function uninstall()
 {
     foreach (self::getScopes() as $scope) {
         $model = new Model($scope);
         while ($model->getHighestCustomVarIndex()) {
             $model->removeCustomVariable();
         }
     }
 }
 private function addCustomVar($scope)
 {
     $this->clearCache();
     $model = new Model($scope);
     $model->addCustomVariable();
 }
Esempio n. 8
0
 public function testExecute_ShouldOutputErrorMessage_IfColumnsDoNotMatch()
 {
     $model = new Model(Model::SCOPE_PAGE);
     $model->removeCustomVariable();
     $this->assertContains('There is a problem with your custom variables configuration', $this->executeCommand());
 }
 private function getNumberOfChangesToPerform($numVarsToSet)
 {
     $numChangesToPerform = 0;
     foreach (Model::getScopes() as $scope) {
         $model = new Model($scope);
         $numCurrentCustomVars = $model->getCurrentNumCustomVars();
         $numChangesToPerform += $this->getAbsoluteDifference($numCurrentCustomVars, $numVarsToSet);
     }
     return $numChangesToPerform;
 }
 public static function getSegmentsMetadata($idSite)
 {
     // Refresh cache for CustomVariables\Model
     Cache::clearCacheGeneral();
     \Piwik\Plugins\CustomVariables\Model::install();
     // Segment matching NONE
     $segments = \Piwik\Plugins\API\API::getInstance()->getSegmentsMetadata($idSite);
     return $segments;
 }