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]; }
/** * 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]; }
public static function uninstall() { foreach (self::getScopes() as $scope) { $model = new Model($scope); while ($model->getHighestCustomVarIndex()) { $model->removeCustomVariable(); } } }
private function printChanges($scope, $numVarsToSet, OutputInterface $output) { $model = new Model($scope); $scopeName = $model->getScopeName(); $highestIndex = $model->getHighestCustomVarIndex(); $numCurrentCustomVars = $model->getCurrentNumCustomVars(); $numVarsDifference = $this->getAbsoluteDifference($numCurrentCustomVars, $numVarsToSet); $output->writeln(''); $output->writeln(sprintf('Scope "%s"', $scopeName)); if ($numVarsToSet > $numCurrentCustomVars) { $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 = $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)); $output->writeln('<comment>This is an irreversible change</comment>'); } }