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@gmail.com>2015-08-29 14:02:01 +0300
committerThomas Steur <thomas.steur@gmail.com>2015-08-29 14:02:01 +0300
commit1196447c73918b41a61bb38e17044067ca9d88a6 (patch)
treec0a43ded9671c115f53c5436a44021684c8888d1 /plugins/CustomVariables/CustomVariables.php
parent96ae06bdeff514e579237776bd148794003af262 (diff)
return min amount of available custom variables across tables instead of maximum
Diffstat (limited to 'plugins/CustomVariables/CustomVariables.php')
-rw-r--r--plugins/CustomVariables/CustomVariables.php32
1 files changed, 24 insertions, 8 deletions
diff --git a/plugins/CustomVariables/CustomVariables.php b/plugins/CustomVariables/CustomVariables.php
index 64a7c9ea05..7a37808909 100644
--- a/plugins/CustomVariables/CustomVariables.php
+++ b/plugins/CustomVariables/CustomVariables.php
@@ -40,7 +40,7 @@ class CustomVariables extends \Piwik\Plugin
{
$customVariables = array();
- $maxCustomVariables = self::getMaxCustomVariables();
+ $maxCustomVariables = self::getNumUsableCustomVariables();
for ($i = 1; $i <= $maxCustomVariables; $i++) {
if (!empty($details['custom_var_k' . $i])) {
@@ -63,25 +63,41 @@ class CustomVariables extends \Piwik\Plugin
return 200;
}
- public static function getMaxCustomVariables()
+ /**
+ * 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.MaxNumCustomVariables';
+ $cacheKey = 'CustomVariables.NumUsableCustomVariables';
if (!array_key_exists($cacheKey, $cache)) {
- $maxCustomVar = 0;
+ $minCustomVar = null;
foreach (Model::getScopes() as $scope) {
$model = new Model($scope);
$highestIndex = $model->getHighestCustomVarIndex();
- if ($highestIndex > $maxCustomVar) {
- $maxCustomVar = $highestIndex;
+ if (!isset($minCustomVar)) {
+ $minCustomVar = $highestIndex;
}
+
+ if ($highestIndex < $minCustomVar) {
+ $minCustomVar = $highestIndex;
+ }
+ }
+
+ if (!isset($minCustomVar)) {
+ $minCustomVar = 0;
}
- $cache[$cacheKey] = $maxCustomVar;
+ $cache[$cacheKey] = $minCustomVar;
Cache::setCacheGeneral($cache);
}
@@ -90,7 +106,7 @@ class CustomVariables extends \Piwik\Plugin
public function getSegmentsMetadata(&$segments)
{
- $maxCustomVariables = self::getMaxCustomVariables();
+ $maxCustomVariables = self::getNumUsableCustomVariables();
for ($i = 1; $i <= $maxCustomVariables; $i++) {
$segments[] = array(