From c889ccf197ced90c84d8692cabd42a16194810d4 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Mon, 4 Sep 2023 16:48:56 +0200 Subject: [PATCH 1/2] Disable userid segment if visitor profile is disabled --- plugins/CoreHome/Columns/UserId.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/CoreHome/Columns/UserId.php b/plugins/CoreHome/Columns/UserId.php index 823743008f8..64c7d8c9106 100644 --- a/plugins/CoreHome/Columns/UserId.php +++ b/plugins/CoreHome/Columns/UserId.php @@ -9,11 +9,14 @@ namespace Piwik\Plugins\CoreHome\Columns; use Piwik\Cache; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\DataTable; use Piwik\DataTable\Map; use Piwik\Metrics; use Piwik\Plugin; use Piwik\Plugin\Dimension\VisitDimension; +use Piwik\Plugins\Live\Live; +use Piwik\Segment\SegmentsList; use Piwik\Tracker\Request; use Piwik\Tracker\Visitor; use Piwik\Tracker\Action; @@ -45,6 +48,14 @@ public function __construct() } } + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) + { + // Configure userId segment only if visitor profile is available + if (Live::isVisitorProfileEnabled()) { + parent::configureSegments($segmentsList, $dimensionSegmentFactory); + } + } + /** * @param Request $request * @param Visitor $visitor From a444ec4c0598f60fa04056216fdef9da1c8c1dfe Mon Sep 17 00:00:00 2001 From: sgiehl Date: Mon, 4 Sep 2023 17:03:01 +0200 Subject: [PATCH 2/2] adds test --- plugins/Live/tests/System/ApiTest.php | 9 +++++++++ .../test_disabledProfile__VisitsSummary.get_day.xml | 6 ++++++ 2 files changed, 15 insertions(+) create mode 100644 plugins/Live/tests/System/expected/test_disabledProfile__VisitsSummary.get_day.xml diff --git a/plugins/Live/tests/System/ApiTest.php b/plugins/Live/tests/System/ApiTest.php index c8b26b78886..bdfa3bfd852 100644 --- a/plugins/Live/tests/System/ApiTest.php +++ b/plugins/Live/tests/System/ApiTest.php @@ -276,6 +276,15 @@ public function testVisitorIdSegmentWithDisabledProfileForSite() ], 'testSuffix' => 'disabledProfile2' ]); + + // user id segment should be disabled if visitor profile isn't available + $this->runApiTests('VisitsSummary.get', [ + 'idSite' => 1, + 'date' => self::$fixture->dateTime, + 'periods' => ['day'], + 'segment' => 'userId==' . urlencode('new-email@example.com'), + 'testSuffix' => 'disabledProfile', + ]); } public static function getOutputPrefix() diff --git a/plugins/Live/tests/System/expected/test_disabledProfile__VisitsSummary.get_day.xml b/plugins/Live/tests/System/expected/test_disabledProfile__VisitsSummary.get_day.xml new file mode 100644 index 00000000000..72facf7ca25 --- /dev/null +++ b/plugins/Live/tests/System/expected/test_disabledProfile__VisitsSummary.get_day.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file