diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2021-02-02 04:33:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-02 04:33:54 +0300 |
commit | 41ca1a79e702a3330299db6d6552b81ed77c4f23 (patch) | |
tree | 71bd3481c0554729190840a6a4aba70d55a845a4 | |
parent | 25a2da15d49e0a5170e844cefacea7d6bdd49837 (diff) |
Allow filtering for invalidations for specific reports in core:archive (mostly for automation purposes). (#16991)
-rw-r--r-- | core/CronArchive/ArchiveFilter.php | 20 | ||||
-rw-r--r-- | plugins/CoreConsole/Commands/CoreArchiver.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/CronArchive/ArchiveFilterTest.php | 27 |
3 files changed, 48 insertions, 1 deletions
diff --git a/core/CronArchive/ArchiveFilter.php b/core/CronArchive/ArchiveFilter.php index 7789ed556b..c3686aaa59 100644 --- a/core/CronArchive/ArchiveFilter.php +++ b/core/CronArchive/ArchiveFilter.php @@ -53,6 +53,13 @@ class ArchiveFilter */ private $skipSegmentsForToday = false; + /** + * If enabled, the only invalidations that will be processed are for the specific plugin and report specified + * here. Must be in the format "MyPlugin.myReport". + * @var string|null + */ + private $forceReport = null; + public function __construct() { $this->setRestrictToPeriods(''); @@ -102,6 +109,14 @@ class ArchiveFilter return "period is not specified in --force-periods"; } + if (!empty($this->forceReport) + && (empty($archive['plugin']) + || empty($archive['report']) + || $archive['plugin'] . '.' . $archive['report'] != $this->forceReport) + ) { + return "report is not the same as value specified in --force-report"; + } + return false; } @@ -224,6 +239,11 @@ class ArchiveFilter return $this->skipSegmentsForToday; } + public function setForceReport($forceReport) + { + $this->forceReport = $forceReport; + } + /** * @return array */ diff --git a/plugins/CoreConsole/Commands/CoreArchiver.php b/plugins/CoreConsole/Commands/CoreArchiver.php index 6407f4bbe2..b33396460c 100644 --- a/plugins/CoreConsole/Commands/CoreArchiver.php +++ b/plugins/CoreConsole/Commands/CoreArchiver.php @@ -49,6 +49,7 @@ class CoreArchiver extends ConsoleCommand $archiveFilter->setRestrictToDateRange($input->getOption("force-date-range")); $archiveFilter->setRestrictToPeriods($input->getOption("force-periods")); $archiveFilter->setSkipSegmentsForToday($input->getOption('skip-segments-today')); + $archiveFilter->setForceReport($input->getOption('force-report')); $segmentIds = $input->getOption('force-idsegments'); $segmentIds = explode(',', $segmentIds); @@ -109,5 +110,6 @@ class CoreArchiver extends ConsoleCommand . "useful if you specified --url=https://... or if you are using Piwik with force_ssl=1"); $command->addOption('php-cli-options', null, InputOption::VALUE_OPTIONAL, 'Forwards the PHP configuration options to the PHP CLI command. For example "-d memory_limit=8G". Note: These options are only applied if the archiver actually uses CLI and not HTTP.', $default = ''); $command->addOption('force-all-websites', null, InputOption::VALUE_NONE, 'Force archiving all websites.'); + $command->addOption('force-report', null, InputOption::VALUE_NONE, 'If specified, only processes invalidations for a specific report in a specific plugin. Value must be in the format of "MyPlugin.myReport".'); } } diff --git a/tests/PHPUnit/Integration/CronArchive/ArchiveFilterTest.php b/tests/PHPUnit/Integration/CronArchive/ArchiveFilterTest.php index 3331cbc881..e6a615320a 100644 --- a/tests/PHPUnit/Integration/CronArchive/ArchiveFilterTest.php +++ b/tests/PHPUnit/Integration/CronArchive/ArchiveFilterTest.php @@ -7,7 +7,7 @@ * */ -namespace PHPUnit\Unit\CronArchive; +namespace PHPUnit\Integration\CronArchive; use Piwik\ArchiveProcessor\Rules; use Piwik\CronArchive\ArchiveFilter; @@ -16,8 +16,33 @@ use Piwik\Plugins\SegmentEditor\API as SegmentAPI; use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; +/** + * @group Core + */ class ArchiveFilterTest extends IntegrationTestCase { + + public function test_archiveFilter_filtersOutArchivesWhenForceReportIsSpecified() + { + $filter = new ArchiveFilter(); + $filter->setForceReport('MyPlugin.myName'); + + $result = $filter->filterArchive(['date1' => '2020-03-04', 'date2' => '2020-03-04', 'period' => 1]); + $this->assertEquals('report is not the same as value specified in --force-report', $result); + + $result = $filter->filterArchive(['date1' => '2020-03-04', 'date2' => '2020-03-04', 'period' => 1, 'plugin' => 'MyPlugin']); + $this->assertEquals('report is not the same as value specified in --force-report', $result); + + $result = $filter->filterArchive(['date1' => '2020-03-04', 'date2' => '2020-03-04', 'period' => 1, 'plugin' => 'MyPlugin', 'report' => 'myOtherName']); + $this->assertEquals('report is not the same as value specified in --force-report', $result); + + $result = $filter->filterArchive(['date1' => '2020-03-04', 'date2' => '2020-03-04', 'period' => 1, 'plugin' => 'MyOtherPlugin', 'report' => 'myName']); + $this->assertEquals('report is not the same as value specified in --force-report', $result); + + $result = $filter->filterArchive(['date1' => '2020-03-04', 'date2' => '2020-03-04', 'period' => 1, 'plugin' => 'MyPlugin', 'report' => 'myName']); + $this->assertFalse($result); + } + public function test_setSegmentsToForceFromSegmentIds_CorrectlyGetsSegmentDefinitions_FromSegmentIds() { Rules::setBrowserTriggerArchiving(false); |