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:
authordizzy <diosmosis@users.noreply.github.com>2021-02-25 06:33:43 +0300
committerGitHub <noreply@github.com>2021-02-25 06:33:43 +0300
commit6ad02c966ab903fc3dff56a1804df976d3219574 (patch)
tree947ac60e798962e59da87f919bbb83e8bbe2c95b
parent21cda64860d4e216b4d32a63d4a31b481485f579 (diff)
Only force single plugin archiving for root archive requests. (#17250)
* Only force single plugin archiving for root archive requests. * add test * update expected files
-rw-r--r--core/ArchiveProcessor/Loader.php14
-rw-r--r--core/ArchiveProcessor/Parameters.php2
-rw-r--r--core/ArchiveProcessor/Rules.php4
-rw-r--r--plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_day.xml2
-rw-r--r--plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_week.xml2
-rw-r--r--tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php93
6 files changed, 112 insertions, 5 deletions
diff --git a/core/ArchiveProcessor/Loader.php b/core/ArchiveProcessor/Loader.php
index fef2270f23..338043a39b 100644
--- a/core/ArchiveProcessor/Loader.php
+++ b/core/ArchiveProcessor/Loader.php
@@ -31,6 +31,8 @@ use Psr\Log\LoggerInterface;
*/
class Loader
{
+ private static $archivingDepth = 0;
+
/**
* @var Parameters
*/
@@ -91,7 +93,12 @@ class Loader
public function prepareArchive($pluginName)
{
return Context::changeIdSite($this->params->getSite()->getId(), function () use ($pluginName) {
- return $this->prepareArchiveImpl($pluginName);
+ try {
+ ++self::$archivingDepth;
+ return $this->prepareArchiveImpl($pluginName);
+ } finally {
+ --self::$archivingDepth;
+ }
});
}
@@ -420,4 +427,9 @@ class Loader
$cacheKey = 'Archiving.minVisitTime.' . $idSite;
$cache->delete($cacheKey);
}
+
+ public static function getArchivingDepth()
+ {
+ return self::$archivingDepth;
+ }
}
diff --git a/core/ArchiveProcessor/Parameters.php b/core/ArchiveProcessor/Parameters.php
index d3a23b1e8f..27e410a7ca 100644
--- a/core/ArchiveProcessor/Parameters.php
+++ b/core/ArchiveProcessor/Parameters.php
@@ -297,7 +297,7 @@ class Parameters
public function __toString()
{
- return "[idSite = {$this->getSite()->getId()}, period = {$this->getPeriod()->getLabel()} {$this->getPeriod()->getRangeString()}, segment = {$this->getSegment()->getString()}]";
+ return "[idSite = {$this->getSite()->getId()}, period = {$this->getPeriod()->getLabel()} {$this->getPeriod()->getRangeString()}, segment = {$this->getSegment()->getString()}, plugin = {$this->getRequestedPlugin()}]";
}
/**
diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php
index 5a857a3eda..3a4ada449b 100644
--- a/core/ArchiveProcessor/Rules.php
+++ b/core/ArchiveProcessor/Rules.php
@@ -330,7 +330,9 @@ class Rules
public static function isForceArchivingSinglePlugin()
{
- if (!SettingsServer::isArchivePhpTriggered()) {
+ if (!SettingsServer::isArchivePhpTriggered()
+ || Loader::getArchivingDepth() > 1
+ ) {
return false;
}
diff --git a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_day.xml b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_day.xml
index 8be8d54d20..74f98a20a2 100644
--- a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_day.xml
+++ b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_day.xml
@@ -2,7 +2,7 @@
<results>
<result idSite="1">
<ExamplePlugin_example_metric>3382</ExamplePlugin_example_metric>
- <ExamplePlugin_example_metric2>1</ExamplePlugin_example_metric2>
+ <ExamplePlugin_example_metric2>0</ExamplePlugin_example_metric2>
</result>
<result idSite="2" />
<result idSite="3" />
diff --git a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_week.xml b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_week.xml
index 8be8d54d20..74f98a20a2 100644
--- a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_week.xml
+++ b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_noOptions__ExamplePlugin.getExampleArchivedMetric_week.xml
@@ -2,7 +2,7 @@
<results>
<result idSite="1">
<ExamplePlugin_example_metric>3382</ExamplePlugin_example_metric>
- <ExamplePlugin_example_metric2>1</ExamplePlugin_example_metric2>
+ <ExamplePlugin_example_metric2>0</ExamplePlugin_example_metric2>
</result>
<result idSite="2" />
<result idSite="3" />
diff --git a/tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php b/tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php
index 4745a1c688..cb5d2f931d 100644
--- a/tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php
+++ b/tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php
@@ -40,6 +40,99 @@ class LoaderTest extends IntegrationTestCase
Fixture::createWebsite('2012-02-03 00:00:00');
}
+ public function test_pluginOnlyArchivingDoesNotRelaunchChildArchives()
+ {
+ $_GET['pluginOnly'] = 1;
+ $_GET['trigger'] = 'archivephp';
+
+ $idSite = 1;
+ $dateTime = '2020-01-20 02:03:04';
+ $date = '2020-01-20';
+ $period = 'week';
+ $segment = '';
+ $plugin = 'Actions';
+
+ $t = Fixture::getTracker($idSite, $dateTime);
+ $t->setUrl('http://slkdfj.com');
+ Fixture::checkResponse($t->doTrackPageView('alsdkjf'));
+
+ $periodObj = Factory::build($period, $date);
+ foreach ($periodObj->getSubperiods() as $day) {
+ // archive each day before hand
+ $params = new Parameters(new Site($idSite), $day, new Segment($segment, [$idSite]));
+ $loader = new Loader($params);
+ $loader->prepareArchive($plugin);
+ }
+
+ $existingArchives = $this->getExistingArchives($date);
+ $this->assertEquals([
+ [
+ 'idarchive' => '1',
+ 'name' => 'done.VisitsSummary',
+ 'value' => '1',
+ 'date1' => '2020-01-20',
+ 'date2' => '2020-01-20',
+ 'period' => '1',
+ ],
+ [
+ 'idarchive' => '2',
+ 'name' => 'done.Actions',
+ 'value' => '1',
+ 'date1' => '2020-01-20',
+ 'date2' => '2020-01-20',
+ 'period' => '1',
+ ],
+ ], $existingArchives);
+
+ $params = new Parameters(new Site($idSite), $periodObj, new Segment($segment, [$idSite]));
+
+ $loader = new Loader($params);
+ $loader->prepareArchive($plugin);
+
+ $existingArchives = $this->getExistingArchives($date);
+
+ $this->assertEquals([
+ [
+ 'idarchive' => '1',
+ 'name' => 'done.VisitsSummary',
+ 'value' => '1',
+ 'date1' => '2020-01-20',
+ 'date2' => '2020-01-20',
+ 'period' => '1',
+ ],
+ [
+ 'idarchive' => '2',
+ 'name' => 'done.Actions',
+ 'value' => '1',
+ 'date1' => '2020-01-20',
+ 'date2' => '2020-01-20',
+ 'period' => '1',
+ ],
+ [
+ 'idarchive' => '3',
+ 'name' => 'done.VisitsSummary',
+ 'value' => '1',
+ 'date1' => '2020-01-20',
+ 'date2' => '2020-01-26',
+ 'period' => '2',
+ ],
+ [
+ 'idarchive' => '4',
+ 'name' => 'done.Actions',
+ 'value' => '1',
+ 'date1' => '2020-01-20',
+ 'date2' => '2020-01-26',
+ 'period' => '2',
+ ],
+ ], $existingArchives);
+ }
+
+ private function getExistingArchives($date)
+ {
+ $table = ArchiveTableCreator::getNumericTable(Date::factory($date));
+ return Db::fetchAll("SELECT idarchive, `name`, date1, date2, period, `value` FROM `$table` WHERE `name` LIKE 'done%' ORDER BY idarchive ASC");
+ }
+
/**
* @dataProvider getTestDataForArchiving
*/