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:
authordiosmosis <diosmosis@users.noreply.github.com>2020-11-04 10:19:48 +0300
committerGitHub <noreply@github.com>2020-11-04 10:19:48 +0300
commit375dd9f6933dcf7eeb37df9d2d9f44d16f35a277 (patch)
tree135baa9b8f9f2b2758ab9adf899d4026b8a91218 /plugins/SegmentEditor
parent6b12f37eb630d25dffa13e315b894abda80ed5af (diff)
several changes to emphasize setup and use of auto-archiving rather than real-time processing (#16603)
* several changes to emphasize setup and use of auto-archiving rather than real-time processing * apply some pr feedback * Applying more pr feedback. * apply review fixes * ignore ability to archive segments in real time * another tweak * update tests * fix another test * fix ui tests * update test * fix evolution icon bug * Update TreemapVisualization and update expected screenshots * update screenshots
Diffstat (limited to 'plugins/SegmentEditor')
-rw-r--r--plugins/SegmentEditor/API.php18
-rw-r--r--plugins/SegmentEditor/SegmentEditor.php20
-rw-r--r--plugins/SegmentEditor/SegmentSelectorControl.php1
-rw-r--r--plugins/SegmentEditor/templates/_segmentSelector.twig8
-rw-r--r--plugins/SegmentEditor/tests/Integration/ApiTest.php3
-rw-r--r--plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php24
-rw-r--r--plugins/SegmentEditor/tests/Integration/SegmentQueryDecoratorTest.php5
-rw-r--r--plugins/SegmentEditor/tests/System/UnprocessedSegmentsTest.php26
8 files changed, 69 insertions, 36 deletions
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php
index f2c85c19bc..56cbe91282 100644
--- a/plugins/SegmentEditor/API.php
+++ b/plugins/SegmentEditor/API.php
@@ -9,6 +9,7 @@
namespace Piwik\Plugins\SegmentEditor;
use Exception;
+use Piwik\ArchiveProcessor\Rules;
use Piwik\Common;
use Piwik\Date;
use Piwik\Db;
@@ -107,16 +108,15 @@ class API extends \Piwik\Plugin\API
}
if ($autoArchive) {
- if ($realTimeSegmentsEnabled && !Piwik::isUserHasAdminAccess($idSite)) {
- // pre-processed segment for a given website requires admin access
- throw new Exception(
- "Please contact Support to make these changes on your behalf. ".
- " To modify a pre-processed segment, a user must have admin access or super user access. "
- );
- } elseif (!$realTimeSegmentsEnabled) {
- // we require view access only when only pre processed can be created
- Piwik::checkUserHasViewAccess($idSite);
+ if (Rules::isBrowserTriggerEnabled()) {
+ $message = "Pre-processed segments can only be created if browser triggered archiving is disabled.";
+ if (Piwik::hasUserSuperUserAccess()) {
+ $message .= " To disable browser archiving follow the instructions here: https://matomo.org/docs/setup-auto-archiving/.";
+ }
+ throw new Exception($message);
}
+
+ Piwik::checkUserHasViewAccess($idSite);
}
return $autoArchive;
diff --git a/plugins/SegmentEditor/SegmentEditor.php b/plugins/SegmentEditor/SegmentEditor.php
index 59ac72ee9c..9a6a4fd615 100644
--- a/plugins/SegmentEditor/SegmentEditor.php
+++ b/plugins/SegmentEditor/SegmentEditor.php
@@ -80,7 +80,25 @@ class SegmentEditor extends \Piwik\Plugin
$storedSegments = StaticContainer::get('Piwik\Plugins\SegmentEditor\Services\StoredSegmentService');
$segments = $storedSegments->getAllSegmentsAndIgnoreVisibility();
$numSegments = count($segments);
- $systemSummary[] = new SystemSummary\Item($key = 'segments', Piwik::translate('CoreHome_SystemSummaryNSegments', $numSegments), $value = null, $url = null, $icon = 'icon-segment', $order = 6);
+
+ if (Rules::isBrowserArchivingAvailableForSegments()) {
+ $numAutoArchiveSegments = 0;
+ $numRealTimeSegments = 0;
+ foreach ($segments as $segment) {
+ $autoArchive = (int)$segment['auto_archive'];
+ if (!empty($autoArchive)) {
+ ++$numAutoArchiveSegments;
+ } else {
+ ++$numRealTimeSegments;
+ }
+ }
+
+ $message = Piwik::translate('CoreHome_SystemSummaryNSegmentsWithBreakdown', [$numSegments, $numAutoArchiveSegments, $numRealTimeSegments]);
+ } else {
+ $message = Piwik::translate('CoreHome_SystemSummaryNSegments', [$numSegments]);
+ }
+
+ $systemSummary[] = new SystemSummary\Item($key = 'segments', $message, $value = null, $url = null, $icon = 'icon-segment', $order = 6);
}
function getSegmentEditorHtml(&$out)
diff --git a/plugins/SegmentEditor/SegmentSelectorControl.php b/plugins/SegmentEditor/SegmentSelectorControl.php
index c1f5c009a6..411209f1b9 100644
--- a/plugins/SegmentEditor/SegmentSelectorControl.php
+++ b/plugins/SegmentEditor/SegmentSelectorControl.php
@@ -86,6 +86,7 @@ class SegmentSelectorControl extends UIControl
'hideSegmentDefinitionChangeMessage',
Piwik::getCurrentUserLogin()
);
+ $this->isBrowserArchivingEnabled = Rules::isBrowserTriggerEnabled();
$this->isVisitorLogEnabled = Manager::getInstance()->isPluginActivated('Live') && Live::isVisitorLogEnabled($this->idSite);
}
diff --git a/plugins/SegmentEditor/templates/_segmentSelector.twig b/plugins/SegmentEditor/templates/_segmentSelector.twig
index 891b4c29a0..602b8a0dd4 100644
--- a/plugins/SegmentEditor/templates/_segmentSelector.twig
+++ b/plugins/SegmentEditor/templates/_segmentSelector.twig
@@ -43,8 +43,8 @@
{{ 'SegmentEditor_ThisSegmentIsVisibleTo'|translate }} <div class="enable_all_users"><strong>
<select class="enable_all_users_select">
- <option value="0">{{ 'SegmentEditor_VisibleToMe'|translate }}</option>
- <option selected="1" value="1">{{ 'SegmentEditor_VisibleToAllUsers'|translate }}</option>
+ <option {% if not isSuperUser %}selected="1"{% endif %} value="0">{{ 'SegmentEditor_VisibleToMe'|translate }}</option>
+ <option {% if isSuperUser %}selected="1"{% endif %} value="1">{{ 'SegmentEditor_VisibleToAllUsers'|translate }}</option>
</select>
</strong></div>
@@ -57,9 +57,9 @@
{{ 'General_And'|translate }} <div class="auto_archive"><strong>
<select class="auto_archive_select">
{% if createRealTimeSegmentsIsEnabled %}
- <option selected="1" value="0">{{ 'SegmentEditor_AutoArchiveRealTime'|translate }} {{ 'General_DefaultAppended'|translate }}</option>
+ <option {% if isBrowserArchivingEnabled %}selected="1"{% endif%} value="0">{{ 'SegmentEditor_AutoArchiveRealTime'|translate }} {{ 'General_DefaultAppended'|translate }}</option>
{% endif %}
- <option {% if not createRealTimeSegmentsIsEnabled %}selected="1"{% endif %} value="1">{{ 'SegmentEditor_AutoArchivePreProcessed'|translate }} </option>
+ <option {% if not isBrowserArchivingEnabled or not createRealTimeSegmentsIsEnabled %}selected="1"{% endif %} value="1">{{ 'SegmentEditor_AutoArchivePreProcessed'|translate }} </option>
</select>
</strong></div>
diff --git a/plugins/SegmentEditor/tests/Integration/ApiTest.php b/plugins/SegmentEditor/tests/Integration/ApiTest.php
index 88bef59bad..13e0fd3357 100644
--- a/plugins/SegmentEditor/tests/Integration/ApiTest.php
+++ b/plugins/SegmentEditor/tests/Integration/ApiTest.php
@@ -8,6 +8,7 @@
namespace Piwik\Plugins\SegmentEditor\tests\Integration;
+use Piwik\ArchiveProcessor\Rules;
use Piwik\Plugins\SegmentEditor\API;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\Mock\FakeAccess;
@@ -152,6 +153,7 @@ class ApiTest extends IntegrationTestCase
*/
protected function createSegments()
{
+ Rules::setBrowserTriggerArchiving(false);
$this->setAdminUser();
$this->api->add('segment 1', 'visitCount<2', $idSite = 1, $autoArchive = true, $enableAllUsers = false);
$this->api->add('segment 2', 'countryCode==fr', $idSite = 2, $autoArchive = false, $enableAllUsers = false);
@@ -170,6 +172,7 @@ class ApiTest extends IntegrationTestCase
$this->setAnotherSuperUser();
$this->api->add('segment 9', 'countryCode!=fr', $idSite = false, $autoArchive = false, $enableAllUsers = true);
+ Rules::setBrowserTriggerArchiving(true);
}
diff --git a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php
index 07e2152739..95ed3c12bb 100644
--- a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php
+++ b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php
@@ -8,6 +8,7 @@
namespace Piwik\Plugins\SegmentEditor\tests\Integration;
+use Piwik\ArchiveProcessor\Rules;
use Piwik\Date;
use Piwik\Piwik;
use Piwik\Plugins\SegmentEditor\API;
@@ -47,16 +48,13 @@ class SegmentEditorTest extends IntegrationTestCase
*/
public function testAddInvalidSegment_ShouldThrow()
{
- try {
- API::getInstance()->add('name', 'test==test2');
- $this->fail("Exception not raised.");
- } catch (Exception $expected) {
- }
- try {
- API::getInstance()->add('name', 'test');
- $this->fail("Exception not raised.");
- } catch (Exception $expected) {
- }
+ $this->expectException(\Exception::class);
+
+ API::getInstance()->add('name', 'test==test2');
+ $this->fail("Exception not raised.");
+
+ API::getInstance()->add('name', 'test');
+ $this->fail("Exception not raised.");
}
/**
@@ -90,6 +88,8 @@ class SegmentEditorTest extends IntegrationTestCase
*/
public function test_AddAndGet_AnotherSegment()
{
+ Rules::setBrowserTriggerArchiving(false);
+
$name = 'name';
$definition = 'searches>1,visitIp!=127.0.0.1';
$idSegment = API::getInstance()->add($name, $definition, $idSite = 1, $autoArchive = 1, $enabledAllUsers = 1);
@@ -135,6 +135,8 @@ class SegmentEditorTest extends IntegrationTestCase
*/
public function test_UpdateSegment()
{
+ Rules::setBrowserTriggerArchiving(false);
+
$name = 'name"';
$definition = 'searches>1,visitIp!=127.0.0.1';
$nameSegment1 = 'hello';
@@ -179,6 +181,8 @@ class SegmentEditorTest extends IntegrationTestCase
*/
public function test_deleteSegment()
{
+ Rules::setBrowserTriggerArchiving(false);
+
$idSegment1 = API::getInstance()->add('name 1', 'searches==0', $idSite = 1, $autoArchive = 1, $enabledAllUsers = 1);
$idSegment2 = API::getInstance()->add('name 2', 'searches>1,visitIp!=127.0.0.1', $idSite = 1, $autoArchive = 1, $enabledAllUsers = 1);
diff --git a/plugins/SegmentEditor/tests/Integration/SegmentQueryDecoratorTest.php b/plugins/SegmentEditor/tests/Integration/SegmentQueryDecoratorTest.php
index e9d18a63fd..7cf0c46de3 100644
--- a/plugins/SegmentEditor/tests/Integration/SegmentQueryDecoratorTest.php
+++ b/plugins/SegmentEditor/tests/Integration/SegmentQueryDecoratorTest.php
@@ -8,6 +8,7 @@
namespace Piwik\Plugins\SegmentEditor\tests\Integration;
+use Piwik\ArchiveProcessor\Rules;
use Piwik\Plugins\SegmentEditor\API;
use Piwik\Plugins\SegmentEditor\SegmentQueryDecorator;
use Piwik\Segment;
@@ -36,6 +37,8 @@ class SegmentQueryDecoratorTest extends IntegrationTestCase
$this->segmentQueryDecorator = self::$fixture->piwikEnvironment->getContainer()->get(
'Piwik\Plugins\SegmentEditor\SegmentQueryDecorator');
+ Rules::setBrowserTriggerArchiving(false);
+
/** @var API $segmentEditorApi */
$segmentEditorApi = self::$fixture->piwikEnvironment->getContainer()->get(
'Piwik\Plugins\SegmentEditor\API');
@@ -47,6 +50,8 @@ class SegmentQueryDecoratorTest extends IntegrationTestCase
// test that segments w/ auto archive == false are included
$segmentEditorApi->add('segment 5', 'visitCount<2', 3, $autoArchive = false);
$segmentEditorApi->add('segment 6', 'countryCode!=fr', 3, $autoArchive = false);
+
+ Rules::setBrowserTriggerArchiving(true);
}
/**
diff --git a/plugins/SegmentEditor/tests/System/UnprocessedSegmentsTest.php b/plugins/SegmentEditor/tests/System/UnprocessedSegmentsTest.php
index ebb5656e5f..0d0f78c3c4 100644
--- a/plugins/SegmentEditor/tests/System/UnprocessedSegmentsTest.php
+++ b/plugins/SegmentEditor/tests/System/UnprocessedSegmentsTest.php
@@ -69,13 +69,13 @@ class UnprocessedSegmentsTest extends IntegrationTestCase
public function test_apiOutput_whenUnprocessedAutoArchiveSegmentUsed_WithBrowserArchivingDisabled()
{
+ Rules::setBrowserTriggerArchiving(false);
+
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
- Rules::setBrowserTriggerArchiving(false);
-
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
@@ -89,13 +89,13 @@ class UnprocessedSegmentsTest extends IntegrationTestCase
public function test_apiOutput_whenUnprocessedAutoArchiveSegmentUsed_WithBrowserArchivingDisabled_AndEncodedSegment()
{
+ Rules::setBrowserTriggerArchiving(false);
+
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
- Rules::setBrowserTriggerArchiving(false);
-
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
@@ -109,14 +109,16 @@ class UnprocessedSegmentsTest extends IntegrationTestCase
public function test_apiOutput_whenPreprocessedSegmentUsed_WithBrowserArchivingDisabled()
{
+ Rules::setBrowserTriggerArchiving(false);
+
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
+ Rules::setBrowserTriggerArchiving(true);
VisitsSummary\API::getInstance()->get(self::$fixture->idSite, 'week',
- Date::factory(self::$fixture->dateTime)->toString(), self::TEST_SEGMENT); // archive
-
+ Date::factory(self::$fixture->dateTime)->toString(), self::TEST_SEGMENT); // archive (make sure there's data for actual test)
Rules::setBrowserTriggerArchiving(false);
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
@@ -152,6 +154,8 @@ class UnprocessedSegmentsTest extends IntegrationTestCase
{
$this->clearLogData();
+ Rules::setBrowserTriggerArchiving(false);
+
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
@@ -160,8 +164,6 @@ class UnprocessedSegmentsTest extends IntegrationTestCase
VisitsSummary\API::getInstance()->get(self::$fixture->idSite, 'week',
Date::factory(self::$fixture->dateTime)->toString(), self::TEST_SEGMENT); // archive
- Rules::setBrowserTriggerArchiving(false);
-
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
@@ -177,13 +179,13 @@ class UnprocessedSegmentsTest extends IntegrationTestCase
{
$this->clearLogData();
+ Rules::setBrowserTriggerArchiving(false);
+
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
- Rules::setBrowserTriggerArchiving(false);
-
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
@@ -197,13 +199,13 @@ class UnprocessedSegmentsTest extends IntegrationTestCase
public function test_apiOutput_whenMultipleSitesRequested_OneWithDataOneNot_AndBrowserArchivingDisabled()
{
+ Rules::setBrowserTriggerArchiving(false);
+
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, $idSite = false, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
- Rules::setBrowserTriggerArchiving(false);
-
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));