From 88797d70be882db2a56cd876fed1063fc1cd929c Mon Sep 17 00:00:00 2001 From: Peter Zhang Date: Sat, 8 Jan 2022 01:20:44 +1300 Subject: dependent archive never run (#18403) * Update ArchiveProcessor.php set plugin not include UserCountry * Update ArchiveProcessor.php update processer * Update ArchiveProcessor.php remove hardcode plugin name * add tests add tests * fix test Co-authored-by: sgiehl --- core/ArchiveProcessor.php | 5 +++-- plugins/Goals/tests/System/ProcessDependentArchiveTest.php | 10 ++++++++-- tests/PHPUnit/Integration/ArchiveTest.php | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php index 09bfeb2428..2fa72d2dbb 100644 --- a/core/ArchiveProcessor.php +++ b/core/ArchiveProcessor.php @@ -679,8 +679,9 @@ class ArchiveProcessor // vs here we would use // userId!@%40matomo.org;userId!=hello%40matomo.org;visitorType==new // thus these would result in different segment hashes and therefore the reports would either show 0 or archive the data twice - $newSegment = Segment::combine($params->getSegment()->getOriginalString(), SegmentExpression::AND_DELIMITER, $segment); - if ($newSegment === $segment && $params->getRequestedPlugin() === $plugin) { // being processed now + $originSegmentString = $params->getSegment()->getOriginalString(); + $newSegment = Segment::combine($originSegmentString, SegmentExpression::AND_DELIMITER, $segment); + if (!empty($originSegmentString) && $newSegment === $segment && $params->getRequestedPlugin() === $plugin) { // being processed now return; } diff --git a/plugins/Goals/tests/System/ProcessDependentArchiveTest.php b/plugins/Goals/tests/System/ProcessDependentArchiveTest.php index f700e20b5a..4e131027b7 100644 --- a/plugins/Goals/tests/System/ProcessDependentArchiveTest.php +++ b/plugins/Goals/tests/System/ProcessDependentArchiveTest.php @@ -34,6 +34,12 @@ class ProcessDependentArchiveTest extends SystemTestCase parent::tearDown(); } + public function test_numArchivesCreated_day() + { + API::getInstance()->getMetrics(self::$fixture->idSite, 'day', '2009-01-04'); + $this->assertNumRangeArchives(5, 1); // days; + } + public function test_numArchivesCreated() { API::getInstance()->get(self::$fixture->idSite, 'range', $this->requestRange); @@ -46,9 +52,9 @@ class ProcessDependentArchiveTest extends SystemTestCase $this->assertNumRangeArchives(6); } - private function assertNumRangeArchives($expectedArchives) + private function assertNumRangeArchives($expectedArchives,$period = 5) { - $archives = Db::fetchAll('SELECT `name` from ' . Common::prefixTable($this->archiveTable) . ' WHERE period = 5 and `name` like "done%"'); + $archives = Db::fetchAll('SELECT `name` from ' . Common::prefixTable($this->archiveTable) . ' WHERE period = '.$period.' and `name` like "done%"'); $numArchives = count($archives); $message = sprintf('Expected archives: %s, got: %s. These were the archives %s', $expectedArchives, $numArchives, json_encode($archives)); $this->assertEquals($expectedArchives, $numArchives, $message); diff --git a/tests/PHPUnit/Integration/ArchiveTest.php b/tests/PHPUnit/Integration/ArchiveTest.php index 820dfe019c..2ca52744de 100644 --- a/tests/PHPUnit/Integration/ArchiveTest.php +++ b/tests/PHPUnit/Integration/ArchiveTest.php @@ -237,7 +237,7 @@ class ArchiveTest extends IntegrationTestCase $expected = [ ['idarchive' => '2', 'date1' => '2020-03-04', 'date2' => '2020-03-04', 'name' => 'done', 'value' => '1'], ['idarchive' => '13', 'date1' => '2020-03-05', 'date2' => '2020-03-05', 'name' => 'done', 'value' => '1'], - ['idarchive' => '16', 'date1' => '2020-03-04', 'date2' => '2020-03-05', 'name' => 'done.VisitsSummary', 'value' => '1'], + ['idarchive' => '18', 'date1' => '2020-03-04', 'date2' => '2020-03-05', 'name' => 'done.VisitsSummary', 'value' => '1'], ]; $this->assertEquals($expected, $archives); } -- cgit v1.2.3