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:
authorKate Butler <kate@innocraft.com>2019-10-16 04:01:06 +0300
committerThomas Steur <tsteur@users.noreply.github.com>2019-10-16 04:01:06 +0300
commit8b2964a968825ede0e12de424608313563bb7f55 (patch)
treebfd77f0967eff1f6c5628ef21b7545246f71c594 /plugins/CoreAdminHome
parentd26202219e74898d583391b17959bf7bd74cb51d (diff)
Allow date ranges to be passed to core:invalidate-report-data (#14450)
Diffstat (limited to 'plugins/CoreAdminHome')
-rw-r--r--plugins/CoreAdminHome/Commands/InvalidateReportData.php40
-rw-r--r--plugins/CoreAdminHome/tests/Integration/Commands/InvalidateReportDataTest.php126
2 files changed, 158 insertions, 8 deletions
diff --git a/plugins/CoreAdminHome/Commands/InvalidateReportData.php b/plugins/CoreAdminHome/Commands/InvalidateReportData.php
index b8abd737f6..75878a48f1 100644
--- a/plugins/CoreAdminHome/Commands/InvalidateReportData.php
+++ b/plugins/CoreAdminHome/Commands/InvalidateReportData.php
@@ -71,6 +71,9 @@ class InvalidateReportData extends ConsoleCommand
$segments = $this->getSegmentsToInvalidateFor($input, $sites);
foreach ($periodTypes as $periodType) {
+ if ($periodType === 'range') {
+ continue; // special handling for range below
+ }
foreach ($dateRanges as $dateRange) {
foreach ($segments as $segment) {
$segmentStr = $segment ? $segment->getString() : '';
@@ -93,6 +96,31 @@ class InvalidateReportData extends ConsoleCommand
}
}
}
+
+ $periods = trim($input->getOption('periods'));
+ $isUsingAllOption = $periods === self::ALL_OPTION_VALUE;
+ if ($isUsingAllOption || in_array('range', $periodTypes)) {
+ $rangeDates = array();
+ foreach ($dateRanges as $dateRange) {
+ if ($isUsingAllOption
+ && !Period::isMultiplePeriod($dateRange, 'day')) {
+ continue; // not a range, nothing to do... only when "all" option is used
+ }
+
+ $rangeDates[] = $this->getPeriodDates('range', $dateRange);
+ }
+ if (!empty($rangeDates)) {
+ foreach ($segments as $segment) {
+ $segmentStr = $segment ? $segment->getString() : '';
+ if ($dryRun) {
+ $dateRangeStr = implode($dateRanges, ';');
+ $output->writeln("Invalidating range periods overlapping $dateRangeStr [segment = $segmentStr]...");
+ } else {
+ $invalidator->markArchivesOverlappingRangeAsInvalidated($sites, $rangeDates, $segment);
+ }
+ }
+ }
+ }
}
private function getSitesToInvalidateFor(InputInterface $input)
@@ -123,7 +151,6 @@ class InvalidateReportData extends ConsoleCommand
if ($periods == self::ALL_OPTION_VALUE) {
$result = array_keys(Piwik::$idPeriods);
- unset($result[4]); // remove 'range' period
return $result;
}
@@ -131,11 +158,6 @@ class InvalidateReportData extends ConsoleCommand
$periods = array_map('trim', $periods);
foreach ($periods as $periodIdentifier) {
- if ($periodIdentifier == 'range') {
- throw new \InvalidArgumentException(
- "Invalid period type: invalidating range periods is not currently supported.");
- }
-
if (!isset(Piwik::$idPeriods[$periodIdentifier])) {
throw new \InvalidArgumentException("Invalid period type '$periodIdentifier' supplied in --periods.");
}
@@ -165,13 +187,17 @@ class InvalidateReportData extends ConsoleCommand
}
try {
+
$period = PeriodFactory::build($periodType, $dateRange);
} catch (\Exception $ex) {
throw new \InvalidArgumentException("Invalid date or date range specifier '$dateRange'", $code = 0, $ex);
}
$result = array();
- if ($period instanceof Range) {
+ if ($periodType === 'range') {
+ $result[] = $period->getDateStart();
+ $result[] = $period->getDateEnd();
+ } elseif ($period instanceof Range) {
foreach ($period->getSubperiods() as $subperiod) {
$result[] = $subperiod->getDateStart();
}
diff --git a/plugins/CoreAdminHome/tests/Integration/Commands/InvalidateReportDataTest.php b/plugins/CoreAdminHome/tests/Integration/Commands/InvalidateReportDataTest.php
index 542b3117e5..ccbbba8d4d 100644
--- a/plugins/CoreAdminHome/tests/Integration/Commands/InvalidateReportDataTest.php
+++ b/plugins/CoreAdminHome/tests/Integration/Commands/InvalidateReportDataTest.php
@@ -74,7 +74,6 @@ class InvalidateReportDataTest extends ConsoleCommandTestCase
{
return array(
array('cranberries'),
- array('range'),
);
}
@@ -144,6 +143,131 @@ class InvalidateReportDataTest extends ConsoleCommandTestCase
}
}
+ public function test_Command_InvalidateDateRange()
+ {
+ $code = $this->applicationTester->run(array(
+ 'command' => 'core:invalidate-report-data',
+ '--dates' => array('2019-01-01,2019-01-09'),
+ '--periods' => 'range',
+ '--sites' => '1',
+ '--dry-run' => true,
+ '-vvv' => true,
+ ));
+
+ $this->assertEquals(0, $code, $this->getCommandDisplayOutputErrorMessage());
+ $this->assertContains("Invalidating range periods overlapping 2019-01-01,2019-01-09 [segment = ]", $this->applicationTester->getDisplay());
+ }
+
+ public function test_Command_InvalidateDateRange_invalidDate()
+ {
+ $code = $this->applicationTester->run(array(
+ 'command' => 'core:invalidate-report-data',
+ '--dates' => array('2019-01-01,2019-01--09'),
+ '--periods' => 'range',
+ '--sites' => '1',
+ '--dry-run' => true,
+ '-vvv' => true,
+ ));
+
+ $this->assertNotEquals(0, $code, $this->getCommandDisplayOutputErrorMessage());
+ $this->assertContains("The date '2019-01-01,2019-01--09' is not a correct date range", $this->applicationTester->getDisplay());
+ }
+
+ public function test_Command_InvalidateDateRange_onlyOneDate()
+ {
+ $code = $this->applicationTester->run(array(
+ 'command' => 'core:invalidate-report-data',
+ '--dates' => array('2019-01-01'),
+ '--periods' => 'range',
+ '--sites' => '1',
+ '--dry-run' => true,
+ '-vvv' => true,
+ ));
+
+ $this->assertNotEquals(0, $code, $this->getCommandDisplayOutputErrorMessage());
+ $this->assertContains("The date '2019-01-01' is not a correct date range", $this->applicationTester->getDisplay());
+ }
+
+ public function test_Command_InvalidateDateRange_tooManyDatesInRange()
+ {
+ $code = $this->applicationTester->run(array(
+ 'command' => 'core:invalidate-report-data',
+ '--dates' => array('2019-01-01,2019-01-09,2019-01-12,2019-01-15'),
+ '--periods' => 'range',
+ '--sites' => '1',
+ '--dry-run' => true,
+ '-vvv' => true,
+ ));
+
+ $this->assertNotEquals(0, $code, $this->getCommandDisplayOutputErrorMessage());
+ $this->assertContains("The date '2019-01-01,2019-01-09,2019-01-12,2019-01-15' is not a correct date range", $this->applicationTester->getDisplay());
+ }
+
+ public function test_Command_InvalidateDateRange_multipleDateRanges()
+ {
+ $code = $this->applicationTester->run(array(
+ 'command' => 'core:invalidate-report-data',
+ '--dates' => array('2019-01-01,2019-01-09', '2019-01-12,2019-01-15'),
+ '--periods' => 'range',
+ '--sites' => '1',
+ '--dry-run' => true,
+ '-vvv' => true,
+ ));
+
+ $this->assertEquals(0, $code, $this->getCommandDisplayOutputErrorMessage());
+ $this->assertContains("Invalidating range periods overlapping 2019-01-01,2019-01-09;2019-01-12,2019-01-15", $this->applicationTester->getDisplay());
+ }
+
+ public function test_Command_InvalidateDateRange_invalidateAllPeriodTypesSkipsRangeWhenNotRangeDAte()
+ {
+ $code = $this->applicationTester->run(array(
+ 'command' => 'core:invalidate-report-data',
+ '--dates' => array('2019-01-01'),
+ '--periods' => 'all',
+ '--sites' => '1',
+ '--dry-run' => true,
+ '-vvv' => true,
+ ));
+
+ $this->assertEquals(0, $code, $this->getCommandDisplayOutputErrorMessage());
+ $this->assertNotContains("range", $this->applicationTester->getDisplay());
+ $this->assertNotContains("Range", $this->applicationTester->getDisplay());
+ }
+
+ public function test_Command_InvalidateDateRange_invalidateAllPeriodTypes()
+ {
+ $code = $this->applicationTester->run(array(
+ 'command' => 'core:invalidate-report-data',
+ '--dates' => array('2019-01-01,2019-01-09'),
+ '--periods' => 'all',
+ '--sites' => '1',
+ '--dry-run' => true,
+ '-vvv' => true,
+ ));
+
+ $this->assertEquals(0, $code, $this->getCommandDisplayOutputErrorMessage());
+ $this->assertContains("Invalidating day periods in 2019-01-01,2019-01-09 [segment = ]", $this->applicationTester->getDisplay());
+ $this->assertContains("Invalidating week periods in 2019-01-01,2019-01-09 [segment = ]", $this->applicationTester->getDisplay());
+ $this->assertContains("Invalidating month periods in 2019-01-01,2019-01-09 [segment = ]", $this->applicationTester->getDisplay());
+ $this->assertContains("Invalidating year periods in 2019-01-01,2019-01-09 [segment = ]", $this->applicationTester->getDisplay());
+ $this->assertContains("Invalidating range periods overlapping 2019-01-01,2019-01-09 [segment = ]", $this->applicationTester->getDisplay());
+ }
+
+ public function test_Command_InvalidateAll_multipleDateRanges()
+ {
+ $code = $this->applicationTester->run(array(
+ 'command' => 'core:invalidate-report-data',
+ '--dates' => array('2019-01-01,2019-01-09', '2019-01-12,2019-01-13'),
+ '--periods' => 'all',
+ '--sites' => '1',
+ '--dry-run' => true,
+ '-vvv' => true,
+ ));
+
+ $this->assertEquals(0, $code, $this->getCommandDisplayOutputErrorMessage());
+ $this->assertContains("Invalidating range periods overlapping 2019-01-01,2019-01-09;2019-01-12,2019-01-13 [segment = ]", $this->applicationTester->getDisplay());
+ }
+
public function getTestDataForSuccessTests()
{
return array(