Skip to content

Commit

Permalink
refs #3490 wondering whether all tests still pass when converting use…
Browse files Browse the repository at this point in the history
…rid to dimension
  • Loading branch information
tsteur committed Sep 22, 2014
1 parent 6ee31ae commit 856ffca
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 30 deletions.
1 change: 1 addition & 0 deletions core/Columns/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ public static function wasDimensionMovedFromCoreToPlugin($name, $version)
'log_visit.referer_keyword' => 'VARCHAR(255) NULL1',
'log_visit.referer_name' => 'VARCHAR(70) NULL1',
'log_visit.referer_type' => 'TINYINT(1) UNSIGNED NULL1',
'log_visit.user_id' => 'VARCHAR(200) NOT NULL',
'log_link_visit_action.idaction_name' => 'INTEGER(10) UNSIGNED',
'log_link_visit_action.idaction_url' => 'INTEGER(10) UNSIGNED DEFAULT NULL',
'log_link_visit_action.server_time' => 'DATETIME NOT NULL',
Expand Down
1 change: 0 additions & 1 deletion core/Db/Schema/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public function getTablesCreateSql()
idvisitor BINARY(8) NOT NULL,
visit_last_action_time DATETIME NOT NULL,
config_id BINARY(8) NOT NULL,
user_id varchar(200) NULL,
location_ip VARBINARY(16) NOT NULL,
PRIMARY KEY(idvisit),
INDEX index_idsite_config_datetime (idsite, config_id, visit_last_action_time),
Expand Down
6 changes: 0 additions & 6 deletions core/Tracker/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ protected function getNewVisitorInformation($visitor)
'idvisitor' => $this->getVisitorIdcookie($visitor),
'config_id' => $this->getSettingsObject()->getConfigId(),
'location_ip' => $this->getVisitorIp(),
'user_id' => $this->request->getForcedUserId(),
);
}

Expand All @@ -519,11 +518,6 @@ protected function getExistingVisitFieldsToUpdate($visitor, $action, $visitIsCon
$visitor->setVisitorColumn('idvisitor', $this->visitorInfo['idvisitor']);
}

if (strlen($this->request->getForcedUserId()) > 0) {
$valuesToUpdate['user_id'] = $this->request->getForcedUserId();
$visitor->setVisitorColumn('user_id', $valuesToUpdate['user_id']);
}

$dimensions = $this->getAllVisitDimensions();
$valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onExistingVisit', $visitor, $action, $valuesToUpdate);

Expand Down
13 changes: 0 additions & 13 deletions core/Updates/2.7.0-b2.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,14 @@

namespace Piwik\Updates;

use Piwik\Common;
use Piwik\Updater;
use Piwik\Updates;

/**
*/
class Updates_2_7_0_b2 extends Updates
{
static function getSql()
{
return array(
'ALTER TABLE `' . Common::prefixTable('log_visit') . '`
ADD `user_id` varchar(200) NULL AFTER `config_id`
' => array(1060),
);
}

static function update()
{
Updater::updateDatabase(__FILE__, self::getSql());

$pluginManager = \Piwik\Plugin\Manager::getInstance();

try {
Expand Down
74 changes: 74 additions & 0 deletions plugins/CoreHome/Columns/UserId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\CoreHome\Columns;

use Piwik\Plugin\Dimension\VisitDimension;
use Piwik\Tracker\Request;
use Piwik\Tracker\Visitor;
use Piwik\Tracker\Action;

/**
* UserId dimension.
*/
class UserId extends VisitDimension
{
/**
* This will be the name of the column in the log_visit table if a $columnType is specified.
* @var string
*/
protected $columnName = 'user_id';

/**
* If a columnType is defined, we will create this a column in the MySQL table having this type. Please make sure
* MySQL will understand this type. Once you change the column type the Piwik platform will notify the user to
* perform an update which can sometimes take a long time so be careful when choosing the correct column type.
* @var string
*/
protected $columnType = 'VARCHAR(200) NOT NULL';

protected function configureSegments()
{
/*
$segment = new Segment();
$segment->setSegment('userId');
$segment->setCategory('General_Visit');
$segment->setName('CoreHome_UserId');
$segment->setAcceptedValues('Here you should explain which values are accepted/useful: Any number, for instance 1, 2, 3 , 99');
$this->addSegment($segment);*/
}

/**
* @param Request $request
* @param Visitor $visitor
* @param Action|null $action
* @return mixed|false
*/
public function onNewVisit(Request $request, Visitor $visitor, $action)
{
return $request->getForcedUserId();
}

/**
* @param Request $request
* @param Visitor $visitor
* @param Action|null $action
*
* @return mixed|false
*/
public function onExistingVisit(Request $request, Visitor $visitor, $action)
{
$forcedUserId = $request->getForcedUserId();
if (strlen($forcedUserId) > 0) {
return $forcedUserId;
}

return false;
}

}
1 change: 1 addition & 0 deletions plugins/CoreHome/CoreHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function extendVisitorDetails(&$visitor, $details)
{
$instance = new Visitor($details);

$visitor['userId'] = $instance->getUserId();
$visitor['visitorType'] = $instance->getVisitorReturning();
$visitor['visitorTypeIcon'] = $instance->getVisitorReturningIcon();
$visitor['visitConverted'] = $instance->isVisitorGoalConverted();
Expand Down
8 changes: 8 additions & 0 deletions plugins/CoreHome/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,13 @@ function getVisitLengthPretty()
return \Piwik\MetricsFormatter::getPrettyTimeFromSeconds($this->details['visit_total_time']);
}

function getUserId()
{
if (isset($this->details['user_id'])
&& !is_null($this->details['user_id'])) {
return $this->details['user_id'];
}
return false;
}

}
10 changes: 0 additions & 10 deletions plugins/Live/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function getAllVisitorDetails()
'idSite' => $this->getIdSite(),
'idVisit' => $this->getIdVisit(),
'visitIp' => $this->getIp(),
'userId' => $this->getUserId(),
'visitorId' => $this->getVisitorId(),

// => false are placeholders to be filled in API later
Expand Down Expand Up @@ -85,15 +84,6 @@ function getVisitorId()
return false;
}

function getUserId()
{
if (isset($this->details['user_id'])
&& !is_null($this->details['user_id'])) {
return $this->details['user_id'];
}
return false;
}

function getVisitServerHour()
{
return date('G', strtotime($this->details['visit_last_action_time']));
Expand Down

0 comments on commit 856ffca

Please sign in to comment.