update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* Piwik - Open source web analytics
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
@ -15,11 +15,14 @@ use Piwik\Log;
class Model
{
const SCOPE_PAGE = 'log_link_visit_action';
const SCOPE_VISIT = 'log_visit';
const SCOPE_CONVERSION = 'log_conversion';
const DEFAULT_CUSTOM_VAR_COUNT = 5;
const SCOPE_PAGE = 'page';
const SCOPE_VISIT = 'visit';
const SCOPE_CONVERSION = 'conversion';
private $scope = null;
private $table = null;
public function __construct($scope)
{
@ -28,19 +31,25 @@ class Model
}
$this->scope = $scope;
$this->table = Common::prefixTable($this->getTableNameFromScope($scope));
}
private function getTableNameFromScope($scope)
{
// actually we should have a class for each scope but don't want to overengineer it for now
switch ($scope) {
case self::SCOPE_PAGE:
return 'log_link_visit_action';
case self::SCOPE_VISIT:
return 'log_visit';
case self::SCOPE_CONVERSION:
return 'log_conversion';
}
}
public function getScopeName()
{
// actually we should have a class for each scope but don't want to overengineer it for now
switch ($this->scope) {
case self::SCOPE_PAGE:
return 'Page';
case self::SCOPE_VISIT:
return 'Visit';
case self::SCOPE_CONVERSION:
return 'Conversion';
}
return ucfirst($this->scope);
}
/**
@ -95,8 +104,7 @@ class Model
private function getCustomVarColumnNames()
{
$dbTable = $this->getDbTableName();
$columns = Db::getColumnNamesFromTable($dbTable);
$columns = Db::getColumnNamesFromTable($this->table);
$customVarColumns = array_filter($columns, function ($column) {
return false !== strpos($column, 'custom_var_');
@ -107,14 +115,13 @@ class Model
public function removeCustomVariable()
{
$dbTable = $this->getDbTableName();
$index = $this->getHighestCustomVarIndex();
$index = $this->getHighestCustomVarIndex();
if ($index < 1) {
return null;
}
Db::exec(sprintf('ALTER TABLE %s ', $dbTable)
Db::exec(sprintf('ALTER TABLE %s ', $this->table)
. sprintf('DROP COLUMN custom_var_k%d,', $index)
. sprintf('DROP COLUMN custom_var_v%d;', $index));
@ -123,22 +130,16 @@ class Model
public function addCustomVariable()
{
$dbTable = $this->getDbTableName();
$index = $this->getHighestCustomVarIndex() + 1;
$maxLen = CustomVariables::getMaxLengthCustomVariables();
$index = $this->getHighestCustomVarIndex() + 1;
$maxLen = CustomVariables::getMaxLengthCustomVariables();
Db::exec(sprintf('ALTER TABLE %s ', $dbTable)
Db::exec(sprintf('ALTER TABLE %s ', $this->table)
. sprintf('ADD COLUMN custom_var_k%d VARCHAR(%d) DEFAULT NULL,', $index, $maxLen)
. sprintf('ADD COLUMN custom_var_v%d VARCHAR(%d) DEFAULT NULL;', $index, $maxLen));
return $index;
}
private function getDbTableName()
{
return Common::prefixTable($this->scope);
}
public static function getCustomVariableIndexFromFieldName($fieldName)
{
$onlyNumber = str_replace(array('custom_var_k', 'custom_var_v'), '', $fieldName);
@ -159,14 +160,14 @@ class Model
$model = new Model($scope);
try {
$maxCustomVars = 5;
$maxCustomVars = self::DEFAULT_CUSTOM_VAR_COUNT;
$customVarsToAdd = $maxCustomVars - $model->getCurrentNumCustomVars();
for ($index = 0; $index < $customVarsToAdd; $index++) {
$model->addCustomVariable();
}
} catch (\Exception $e) {
Log::warning('Failed to add custom variable: ' . $e->getMessage());
Log::error('Failed to add custom variable: ' . $e->getMessage());
}
}
}