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:
authorStefan Giehl <stefan@matomo.org>2022-04-14 15:14:47 +0300
committerGitHub <noreply@github.com>2022-04-14 15:14:47 +0300
commit4f780a6b1b698de15c1c68e2a72bed8ce0cb613b (patch)
tree56c7d7e8bb3dab664e850a2270659b6cb49acef5
parentc9baad5f9502fe9ee4c70d94a21a1b3942398c62 (diff)
Disable VisitorID segment site dependent (#19083)
* Disable VisitorID segment site dependent * Adds tests * fix test
-rw-r--r--plugins/CoreHome/Columns/VisitorId.php9
-rw-r--r--plugins/Live/tests/System/ApiTest.php49
-rw-r--r--plugins/Live/tests/System/expected/test_disabledProfile2__API.getSuggestedValuesForSegment.xml4
-rw-r--r--plugins/Live/tests/System/expected/test_disabledProfile__API.getSuggestedValuesForSegment.xml6
4 files changed, 59 insertions, 9 deletions
diff --git a/plugins/CoreHome/Columns/VisitorId.php b/plugins/CoreHome/Columns/VisitorId.php
index 108c41b921..ff1596837b 100644
--- a/plugins/CoreHome/Columns/VisitorId.php
+++ b/plugins/CoreHome/Columns/VisitorId.php
@@ -1,4 +1,5 @@
<?php
+
/**
* Matomo - free/libre analytics platform
*
@@ -13,8 +14,8 @@ use Piwik\Columns\MetricsList;
use Piwik\Piwik;
use Piwik\Plugin\ArchivedMetric;
use Piwik\Plugin\Dimension\VisitDimension;
+use Piwik\Plugins\Live\Live;
use Piwik\Segment\SegmentsList;
-use Piwik\Plugins\Live\SystemSettings;
use Piwik\Columns\DimensionSegmentFactory;
/**
@@ -30,7 +31,7 @@ class VisitorId extends VisitDimension
protected $segmentName = 'visitorId';
protected $acceptValues = '34c31e04394bdc63 - any 16 Hexadecimal chars ID, which can be fetched using the Tracking API function getVisitorId()';
protected $allowAnonymous = false;
- protected $sqlFilterValue = array('Piwik\Common', 'convertVisitorIdToBin');
+ protected $sqlFilterValue = ['Piwik\Common', 'convertVisitorIdToBin'];
protected $type = self::TYPE_BINARY;
public function configureMetrics(MetricsList $metricsList, DimensionMetricFactory $dimensionMetricFactory)
@@ -44,9 +45,7 @@ class VisitorId extends VisitDimension
public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory)
{
try {
- $systemSettings = new SystemSettings();
- $visitorProfileEnabled = $systemSettings->disableVisitorProfile->getValue() === false
- && $systemSettings->disableVisitorLog->getValue() === false;
+ $visitorProfileEnabled = Live::isVisitorProfileEnabled();
} catch (\Zend_Db_Exception $e) {
// when running tests the db might not yet be set up when fetching available segments
if (!defined('PIWIK_TEST_MODE') || !PIWIK_TEST_MODE) {
diff --git a/plugins/Live/tests/System/ApiTest.php b/plugins/Live/tests/System/ApiTest.php
index 9236600a75..c8b26b7888 100644
--- a/plugins/Live/tests/System/ApiTest.php
+++ b/plugins/Live/tests/System/ApiTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* Matomo - free/libre analytics platform
*
@@ -11,8 +12,10 @@ namespace Piwik\Plugins\Live\tests\System;
use Piwik\Cache;
use Piwik\Config;
use Piwik\Plugins\API\API;
+use Piwik\Plugins\Live\MeasurableSettings;
use Piwik\Plugins\Live\SystemSettings;
use Piwik\Plugins\Live\tests\Fixtures\ManyVisitsOfSameVisitor;
+use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
/**
@@ -225,9 +228,9 @@ class ApiTest extends SystemTestCase
'format' => 'xml',
'otherRequestParameters' => [
'urls' => [
- urlencode("idSite=1&date=".self::$fixture->dateTime."&period=day&method=Live.getLastVisitsDetails"),
- urlencode("idSite=1&date=".self::$fixture->dateTime."&period=day&method=API.getSuggestedValuesForSegment&segmentName=pageTitle"),
- urlencode("idSite=1&date=".self::$fixture->dateTime."&period=day&method=Live.getVisitorProfile"),
+ urlencode("idSite=1&date=" . self::$fixture->dateTime . "&period=day&method=Live.getLastVisitsDetails"),
+ urlencode("idSite=1&date=" . self::$fixture->dateTime . "&period=day&method=API.getSuggestedValuesForSegment&segmentName=pageTitle"),
+ urlencode("idSite=1&date=" . self::$fixture->dateTime . "&period=day&method=Live.getVisitorProfile"),
]
],
]
@@ -236,6 +239,45 @@ class ApiTest extends SystemTestCase
return $apiToTest;
}
+ public function testVisitorIdSegmentWithDisabledProfileForSite()
+ {
+ $settings = new SystemSettings();
+ $settings->disableVisitorLog->setValue(false);
+ $settings->disableVisitorProfile->setValue(false);
+ $settings->save();
+
+ $settings = new MeasurableSettings(1);
+ $settings->disableVisitorLog->setValue(false);
+ $settings->disableVisitorProfile->setValue(true);
+ $settings->save();
+
+ $date = mktime(0, 0, 0, 1, 1, 2010);
+ $lookBack = ceil((time() - $date) / 86400);
+ API::$_autoSuggestLookBack = $lookBack;
+
+ Fixture::clearInMemoryCaches();
+
+ $this->runApiTests('API.getSuggestedValuesForSegment', [
+ 'idSite' => 1,
+ 'date' => self::$fixture->dateTime,
+ 'periods' => ['day'],
+ 'otherRequestParameters' => [
+ 'segmentName' => 'visitorId',
+ ],
+ 'testSuffix' => 'disabledProfile'
+ ]);
+
+ $this->runApiTests('API.getSuggestedValuesForSegment', [
+ 'idSite' => 2,
+ 'date' => self::$fixture->dateTime,
+ 'periods' => ['day'],
+ 'otherRequestParameters' => [
+ 'segmentName' => 'visitorId',
+ ],
+ 'testSuffix' => 'disabledProfile2'
+ ]);
+ }
+
public static function getOutputPrefix()
{
return '';
@@ -245,7 +287,6 @@ class ApiTest extends SystemTestCase
{
return dirname(__FILE__);
}
-
}
ApiTest::$fixture = new ManyVisitsOfSameVisitor();
diff --git a/plugins/Live/tests/System/expected/test_disabledProfile2__API.getSuggestedValuesForSegment.xml b/plugins/Live/tests/System/expected/test_disabledProfile2__API.getSuggestedValuesForSegment.xml
new file mode 100644
index 0000000000..073719ec4c
--- /dev/null
+++ b/plugins/Live/tests/System/expected/test_disabledProfile2__API.getSuggestedValuesForSegment.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <row>dbc0f004854457f5</row>
+</result> \ No newline at end of file
diff --git a/plugins/Live/tests/System/expected/test_disabledProfile__API.getSuggestedValuesForSegment.xml b/plugins/Live/tests/System/expected/test_disabledProfile__API.getSuggestedValuesForSegment.xml
new file mode 100644
index 0000000000..ef5ac8ed46
--- /dev/null
+++ b/plugins/Live/tests/System/expected/test_disabledProfile__API.getSuggestedValuesForSegment.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <error message="Requested segment visitorId not found.
+
+ --&gt; To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php" />
+</result> \ No newline at end of file