Skip to content

Commit fa4df59

Browse files
sgiehlnathangavin
authored andcommitted
Do not try to populate cache for disabled periods (#23880)
* Do not try to populate cache for disabled periods * adds test
1 parent e613999 commit fa4df59

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

core/ArchiveProcessor/Loader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ private function hasSiteVisitsBetweenTimeframe($idSite, Period $period): bool
678678
$currentPeriod = $period;
679679
do {
680680
$parentPeriodLabel = $currentPeriod->getParentPeriodLabel();
681+
if (!Period\Factory::isPeriodEnabledForAPI($parentPeriodLabel)) {
682+
$parentPeriodLabel = null;
683+
}
681684
if ($parentPeriodLabel) {
682685
$parentPeriod = Period\Factory::build($parentPeriodLabel, $date1);
683686
$cacheKey = CacheId::siteAware(sprintf($cacheKeyStr, $parentPeriod->getLabel(), $parentPeriod->getRangeString()), [$idSite]);

tests/PHPUnit/Integration/CronArchiveTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Piwik\ArchiveProcessor\Parameters;
1313
use Piwik\ArchiveProcessor\Rules;
1414
use Piwik\Common;
15+
use Piwik\Config\GeneralConfig;
1516
use Piwik\Container\StaticContainer;
1617
use Piwik\CronArchive;
1718
use Piwik\DataAccess\ArchiveTableCreator;
@@ -1597,6 +1598,29 @@ public function testShouldNotStopProcessingWhenOneSiteIsInvalid()
15971598
self::assertStringContainsString($expected, $logger->output);
15981599
}
15991600

1601+
public function testShouldSkipYearPeriodWhenDisabled()
1602+
{
1603+
\Piwik\Tests\Framework\Mock\FakeCliMulti::$specifiedResults = [
1604+
'/method=API.get/' => json_encode([['nb_visits' => 1]]),
1605+
];
1606+
1607+
GeneralConfig::setConfigValue('enabled_periods_API', 'day,week,month,range');
1608+
1609+
Fixture::createWebsite('2014-12-12 00:01:02');
1610+
1611+
$tracker = Fixture::getTracker(1, '2020-02-03 12:01:02');
1612+
Fixture::checkResponse($tracker->doTrackPageView('test'));
1613+
1614+
$logger = new FakeLogger();
1615+
1616+
$archiver = new CronArchive($logger);
1617+
$archiver->shouldArchiveSpecifiedSites = [1];
1618+
$archiver->init();
1619+
$archiver->run();
1620+
1621+
self::assertStringNotContainsString('year', $logger->output);
1622+
}
1623+
16001624
public function provideContainerConfig()
16011625
{
16021626
Date::$now = strtotime('2020-02-03 04:05:06');

0 commit comments

Comments
 (0)