diff options
-rw-r--r-- | core/Archive/ArchiveInvalidator.php | 8 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php | 24 |
2 files changed, 32 insertions, 0 deletions
diff --git a/core/Archive/ArchiveInvalidator.php b/core/Archive/ArchiveInvalidator.php index 3e8f84775e..5d34ea826c 100644 --- a/core/Archive/ArchiveInvalidator.php +++ b/core/Archive/ArchiveInvalidator.php @@ -476,6 +476,10 @@ class ArchiveInvalidator $earliestDateToRearchive = $this->getEarliestDateToRearchive(); if (empty($startDate)) { + if (empty($earliestDateToRearchive)) { + return null; // INI setting set to 0 months so no rearchiving + } + $startDate = $earliestDateToRearchive; } else if (!empty($earliestDateToRearchive)) { // don't allow archiving further back than the rearchive_reports_in_past_last_n_months date allows @@ -803,6 +807,10 @@ class ArchiveInvalidator } } + if ($lastNMonthsToInvalidate <= 0) { + return null; + } + return Date::yesterday()->subMonth($lastNMonthsToInvalidate)->setDay(1); } } diff --git a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php index 7325ca852e..a8fb31069d 100644 --- a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php +++ b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php @@ -84,6 +84,30 @@ class ArchiveInvalidatorTest extends IntegrationTestCase $this->invalidator = new ArchiveInvalidator(new Model(), StaticContainer::get(ArchivingStatus::class), new NullLogger()); } + public function test_reArchiveReport_doesNothingIfIniSettingSetToZero() + { + Date::$now = strtotime('2020-06-16 12:00:00'); + + Config::getInstance()->General['rearchive_reports_in_past_last_n_months'] = 'last0'; + + $this->invalidator->reArchiveReport([1], 'VisitsSummary', 'some.Report'); + + $expectedInvalidations = []; + $actualInvalidations = $this->getInvalidatedArchiveTableEntriesSummary(); + + $this->assertEquals($expectedInvalidations, $actualInvalidations); + + // different format + Config::getInstance()->General['rearchive_reports_in_past_last_n_months'] = '0'; + + $this->invalidator->reArchiveReport([1], 'VisitsSummary', 'some.Report'); + + $expectedInvalidations = []; + $actualInvalidations = $this->getInvalidatedArchiveTableEntriesSummary(); + + $this->assertEquals($expectedInvalidations, $actualInvalidations); + } + public function test_removeInvalidationsFromDistributedList_removesEntriesFromList_WhenNoPluginSpecified() { $this->invalidator->scheduleReArchiving([1,2,3], 'ExamplePlugin'); |