diff options
author | Zoltan Flamis <zoltan@innocraft.com> | 2021-04-19 01:18:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-19 01:18:49 +0300 |
commit | 7b1b36c46559ee71c144152a0d95cd41e162e1dc (patch) | |
tree | 3223186fdfd371f5f21d16b7e5acbc03e5a206c6 /plugins/SegmentEditor | |
parent | 84b9f9c33ce6402556008c8764a79747f24b5b0f (diff) |
store segment hash in DB (#17408)
* get segment hash
* convert tab indentations to spaces
* Create 4.3.0-b2.php
* update tests and update file
* bump version
* Update 4.3.0-b3.php
* Update ApiTest.php
* fixing urlencode bugs
* cache segment hashes
* update segment caching
* update segment caching
* add segment cache test
* add testdox to phpunit.xml
* revert phunit.xml
* test investigation
* Update phpunit.xml.dist
* update blobreportlimitingt test
* Revert "update blobreportlimitingt test"
This reverts commit 90fe7355cd1d227193f0b73ddf1d715c8b016616.
* Update phpunit.xml.dist
* Update BlobReportLimitingTest.php
* Update BlobReportLimitingTest.php
* Update SystemTestCase.php
* Update BlobReportLimitingTest.php
* Update SystemTestCase.php
* Update phpunit.xml.dist
* modify mem limit for travis
* Update .travis.yml
* revert travis.yml
* Update SystemTestCase.php
* try test without cache
* test witch cache and gc_disabled
* Revert "test witch cache and gc_disabled"
This reverts commit 7e1d37093c7be648a84b57335edf397c89913758.
* test witch cache and gc_disabled
* use other model method
* refactor test
* Workaround error in Overlay when site has no URLs (#17457)
* Set setting value even if set to NULL so it will still be validated.
* Make sure when creating a site that the urls options is set.
* workaround in Overlay for instances that have an invalid site URL set for some reason
* Add integration tests for changes to SitesManager API.
* revert non-overlay changes
* Add warning if site has no URLs when viewing Overlay.
* add more tests for segment caches
* get segment hash
* convert tab indentations to spaces
* Create 4.3.0-b2.php
* update tests and update file
* bump version
* Update 4.3.0-b3.php
* Update ApiTest.php
* fixing urlencode bugs
* cache segment hashes
* update segment caching
* update segment caching
* add segment cache test
* add testdox to phpunit.xml
* revert phunit.xml
* test investigation
* Update phpunit.xml.dist
* update blobreportlimitingt test
* Revert "update blobreportlimitingt test"
This reverts commit 90fe7355cd1d227193f0b73ddf1d715c8b016616.
* Update phpunit.xml.dist
* Update BlobReportLimitingTest.php
* Update BlobReportLimitingTest.php
* Update SystemTestCase.php
* Update BlobReportLimitingTest.php
* Update SystemTestCase.php
* Update phpunit.xml.dist
* modify mem limit for travis
* Update .travis.yml
* revert travis.yml
* Update SystemTestCase.php
* try test without cache
* test witch cache and gc_disabled
* Revert "test witch cache and gc_disabled"
This reverts commit 7e1d37093c7be648a84b57335edf397c89913758.
* test witch cache and gc_disabled
* use other model method
* refactor test
* add more tests for segment caches
* revert phpunit.xml
* revert phpunit.xml
* add more tests
Co-authored-by: dizzy <diosmosis@users.noreply.github.com>
Diffstat (limited to 'plugins/SegmentEditor')
-rw-r--r-- | plugins/SegmentEditor/API.php | 7 | ||||
-rw-r--r-- | plugins/SegmentEditor/Model.php | 31 | ||||
-rw-r--r-- | plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php | 5 | ||||
-rw-r--r-- | plugins/SegmentEditor/tests/System/ApiTest.php | 33 |
4 files changed, 64 insertions, 12 deletions
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php index 65758b3c64..49b436c3d2 100644 --- a/plugins/SegmentEditor/API.php +++ b/plugins/SegmentEditor/API.php @@ -23,6 +23,7 @@ use Piwik\Config; use Piwik\Segment; use Piwik\Site; use Psr\Log\LoggerInterface; +use Piwik\Cache; /** * The SegmentEditor API lets you add, update, delete custom Segments, and list saved segments. @@ -222,6 +223,8 @@ class API extends \Piwik\Plugin\API $this->getModel()->deleteSegment($idSegment); + Cache::getEagerCache()->flushAll(); + return true; } @@ -280,6 +283,8 @@ class API extends \Piwik\Plugin\API $this->segmentArchiving->reArchiveSegment($bind); } + Cache::getEagerCache()->flushAll(); + return true; } @@ -316,6 +321,8 @@ class API extends \Piwik\Plugin\API $id = $this->getModel()->createSegment($bind); + Cache::getEagerCache()->flushAll(); + if ($autoArchive && !Rules::isBrowserTriggerEnabled() && $this->processNewSegmentsFrom != SegmentArchiving::CREATION_TIME diff --git a/plugins/SegmentEditor/Model.php b/plugins/SegmentEditor/Model.php index 5dccf40b14..f876d2a46c 100644 --- a/plugins/SegmentEditor/Model.php +++ b/plugins/SegmentEditor/Model.php @@ -225,6 +225,9 @@ class Model { $idSegment = (int) $idSegment; + if (isset($segment['definition'])) { + $segment['hash'] = $this->createHash($segment['definition']); + } $db = $this->getDb(); $db->update($this->getTable(), $segment, "idsegment = $idSegment"); @@ -234,6 +237,8 @@ class Model public function createSegment($segment) { $db = $this->getDb(); + + $segment['hash'] = $this->createHash($segment['definition']); $db->insert($this->getTable(), $segment); $id = $db->lastInsertId(); @@ -258,19 +263,25 @@ class Model return "SELECT * FROM " . $this->getTable() . " WHERE $where ORDER BY name ASC"; } + private function createHash($definition) + { + return md5(urldecode($definition)); + } + public static function install() { $segmentTable = "`idsegment` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(255) NOT NULL, - `definition` TEXT NOT NULL, - `login` VARCHAR(100) NOT NULL, - `enable_all_users` tinyint(4) NOT NULL default 0, - `enable_only_idsite` INTEGER(11) NULL, - `auto_archive` tinyint(4) NOT NULL default 0, - `ts_created` TIMESTAMP NULL, - `ts_last_edit` TIMESTAMP NULL, - `deleted` tinyint(4) NOT NULL default 0, - PRIMARY KEY (`idsegment`)"; + `name` VARCHAR(255) NOT NULL, + `definition` TEXT NOT NULL, + `hash` CHAR(32) NULL, + `login` VARCHAR(100) NOT NULL, + `enable_all_users` tinyint(4) NOT NULL default 0, + `enable_only_idsite` INTEGER(11) NULL, + `auto_archive` tinyint(4) NOT NULL default 0, + `ts_created` TIMESTAMP NULL, + `ts_last_edit` TIMESTAMP NULL, + `deleted` tinyint(4) NOT NULL default 0, + PRIMARY KEY (`idsegment`)"; DbHelper::createTable(self::$rawPrefix, $segmentTable); } diff --git a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php index ec594117a9..09430ca9be 100644 --- a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php +++ b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php @@ -72,9 +72,10 @@ class SegmentEditorTest extends IntegrationTestCase $segment = API::getInstance()->get($idSegment); unset($segment['ts_created']); $expected = array( - 'idsegment' => 1, + 'idsegment' => '1', 'name' => $name, 'definition' => $definition, + 'hash' => md5($definition), 'login' => 'superUserLogin', 'enable_all_users' => '0', 'enable_only_idsite' => '0', @@ -104,6 +105,7 @@ class SegmentEditorTest extends IntegrationTestCase 'idsegment' => '1', 'name' => $name, 'definition' => $definition, + 'hash' => md5($definition), 'login' => 'superUserLogin', 'enable_all_users' => '1', 'enable_only_idsite' => '1', @@ -145,6 +147,7 @@ class SegmentEditorTest extends IntegrationTestCase 'idsegment' => $idSegment2, 'name' => 'NEW name', 'definition' => 'searches==0', + 'hash' => md5('searches==0'), 'enable_only_idsite' => '0', 'enable_all_users' => '0', 'auto_archive' => '1', diff --git a/plugins/SegmentEditor/tests/System/ApiTest.php b/plugins/SegmentEditor/tests/System/ApiTest.php index 0ae9dea78c..2b8d881490 100644 --- a/plugins/SegmentEditor/tests/System/ApiTest.php +++ b/plugins/SegmentEditor/tests/System/ApiTest.php @@ -62,4 +62,35 @@ class ApiTest extends SystemTestCase $this->assertEquals($segmentApiHash, $segmentDefinitionHash); } -}
\ No newline at end of file + + /** + * @dataProvider definitionsDataProvider + */ + public function test_generatedSegmentHash($definition) + { + Fixture::createWebsite('2020-03-03 00:00:00'); + + Config::getInstance()->General['enable_browser_archiving_triggering'] = 0; + self::$fixture->getTestEnvironment()->overrideConfig('General', 'enable_browser_archiving_triggering', 0); + self::$fixture->getTestEnvironment()->save(); + + $idSegment = SegmentEditorApi::getInstance()->add('test segment', $definition, 1, 1, 1); + $segment = SegmentEditorApi::getInstance()->get($idSegment); + + $hash = $segment['hash']; + $generatedHash = md5(urldecode($segment['definition'])); + + $this->assertEquals($generatedHash, $hash); + } + + public function definitionsDataProvider() + { + return [ + ['pageUrl=@%252F1'], + ['actions>=1'], + ['operatingSystemName==Ubuntu;browserName==Firefox'], + ['pageUrl==https%253A%252F%252Fmatomo.org%252Fpricing%252F'], + ['visitIp>=80.229.0.0;visitIp<=80.229.255.255'], + ]; + } +} |