diff options
author | diosmosis <benaka@piwik.pro> | 2015-03-06 06:47:08 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-03-06 06:47:08 +0300 |
commit | 746b599f03d93ad82a1a270f610f1cf15787a949 (patch) | |
tree | 2ec8f3705cef57302276edc8a50d0d967c3ea9d8 | |
parent | ca1a5c3c365f3b1e7c3529e0568a9cca60ec754c (diff) |
Refs #7811, do not purge custom ranges in same method as outdated archive purging. Move to a second method in Archive\Purger.
-rw-r--r-- | core/Archive/Purger.php | 4 | ||||
-rw-r--r-- | plugins/CoreAdminHome/Commands/PurgeOldArchiveData.php | 13 | ||||
-rw-r--r-- | plugins/CoreAdminHome/Tasks.php | 5 | ||||
-rw-r--r-- | tests/PHPUnit/Fixtures/RawArchiveDataWithTempAndInvalidated.php | 7 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/Archive/PurgerTest.php | 16 |
5 files changed, 35 insertions, 10 deletions
diff --git a/core/Archive/Purger.php b/core/Archive/Purger.php index 3d91170a37..031decc36d 100644 --- a/core/Archive/Purger.php +++ b/core/Archive/Purger.php @@ -117,8 +117,6 @@ class Purger $this->deleteArchiveIds($dateStart, $idArchivesToDelete); } - $this->deleteArchivesWithPeriodRange($dateStart); // TODO: this is unrelated to outdated archive purging, should be in its own method - Log::debug("Purging temporary archives: done [ purged archives older than %s in %s ] [Deleted IDs: %s]", $purgeArchivesOlderThan, $dateStart->toString("Y-m"), @@ -146,7 +144,7 @@ class Purger * * @param $date Date */ - protected function deleteArchivesWithPeriodRange(Date $date) + public function purgeArchivesWithPeriodRange(Date $date) { $numericTable = ArchiveTableCreator::getNumericTable($date); $blobTable = ArchiveTableCreator::getBlobTable($date); diff --git a/plugins/CoreAdminHome/Commands/PurgeOldArchiveData.php b/plugins/CoreAdminHome/Commands/PurgeOldArchiveData.php index c8a358e721..8c88a7e312 100644 --- a/plugins/CoreAdminHome/Commands/PurgeOldArchiveData.php +++ b/plugins/CoreAdminHome/Commands/PurgeOldArchiveData.php @@ -56,6 +56,7 @@ class PurgeOldArchiveData extends ConsoleCommand array(self::getToday()->toString())); $this->addOption('exclude-outdated', null, InputOption::VALUE_NONE, "Do not purge outdated archive data."); $this->addOption('exclude-invalidated', null, InputOption::VALUE_NONE, "Do not purge invalidated archive data."); + $this->addOption('exclude-ranges', null, InputOption::VALUE_NONE, "Do not purge custom ranges."); $this->addOption('skip-optimize-tables', null, InputOption::VALUE_NONE, "Do not run OPTIMIZE TABLES query on affected archive tables."); $this->setHelp("By default old and invalidated archives are purged. Custom ranges are also purged with outdated archives.\n\n" . "Note: archive purging is done during scheduled task execution, so under normal circumstances, you should not need to " @@ -93,6 +94,18 @@ class PurgeOldArchiveData extends ConsoleCommand } } + $excludeCustomRanges = $input->getOption('exclude-ranges'); + if ($excludeCustomRanges) { + $output->writeln("Skipping purge custom range archives."); + } else { + foreach ($dates as $date) { + $message = sprintf("Purging custom range archives for %s...", $date->toString('Y_m')); + $this->performTimedPurging($output, $message, function () use ($date, $archivePurger) { + $archivePurger->purgeArchivesWithPeriodRange($date); + }); + } + } + $skipOptimizeTables = $input->getOption('skip-optimize-tables'); if ($skipOptimizeTables) { $output->writeln("Skipping OPTIMIZE TABLES."); diff --git a/plugins/CoreAdminHome/Tasks.php b/plugins/CoreAdminHome/Tasks.php index 07398a83e3..ae28788d1d 100644 --- a/plugins/CoreAdminHome/Tasks.php +++ b/plugins/CoreAdminHome/Tasks.php @@ -58,7 +58,10 @@ class Tasks extends \Piwik\Plugin\Tasks // Somehow we may have archive tables created with older dates, prevent exception from being thrown if ($year > 1990) { - $this->archivePurger->purgeOutdatedArchives(Date::factory("$year-$month-15")); + $dateObj = Date::factory("$year-$month-15"); + + $this->archivePurger->purgeOutdatedArchives($dateObj); + $this->archivePurger->purgeArchivesWithPeriodRange($dateObj); } } } diff --git a/tests/PHPUnit/Fixtures/RawArchiveDataWithTempAndInvalidated.php b/tests/PHPUnit/Fixtures/RawArchiveDataWithTempAndInvalidated.php index aa05e9d5b5..a6ef25a89f 100644 --- a/tests/PHPUnit/Fixtures/RawArchiveDataWithTempAndInvalidated.php +++ b/tests/PHPUnit/Fixtures/RawArchiveDataWithTempAndInvalidated.php @@ -343,9 +343,12 @@ class RawArchiveDataWithTempAndInvalidated extends Fixture $this->assertArchivesExist($expectedPresentArchives, $date); } - public function assertCustomRangesNotPurged(Date $date) + public function assertCustomRangesNotPurged(Date $date, $includeTemporary = true) { - $expectedPresentArchives = array(8, 9, 10); + $expectedPresentArchives = array(8, 9); + if ($includeTemporary) { + $expectedPresentArchives[] = 10; + } $this->assertArchivesExist($expectedPresentArchives, $date); } diff --git a/tests/PHPUnit/Integration/Archive/PurgerTest.php b/tests/PHPUnit/Integration/Archive/PurgerTest.php index d97d348954..2b3330ac32 100644 --- a/tests/PHPUnit/Integration/Archive/PurgerTest.php +++ b/tests/PHPUnit/Integration/Archive/PurgerTest.php @@ -58,27 +58,27 @@ class PurgerTest extends IntegrationTestCase $this->configureCustomRangePurging(); } - public function test_purgeOutdatedArchives_PurgesCorrectTemporaryArchives_AndRangeArchives_WhileKeepingNewerTemporaryArchives_WithBrowserTriggeringEnabled() + public function test_purgeOutdatedArchives_PurgesCorrectTemporaryArchives_WhileKeepingNewerTemporaryArchives_WithBrowserTriggeringEnabled() { $this->enableBrowserTriggeredArchiving(); $this->archivePurger->purgeOutdatedArchives($this->february); self::$fixture->assertTemporaryArchivesPurged($browserTriggeringEnabled = true, $this->february); - self::$fixture->assertCustomRangesPurged($this->february); + self::$fixture->assertCustomRangesNotPurged($this->february, $includeTemporary = false); self::$fixture->assertTemporaryArchivesNotPurged($this->january); } - public function test_purgeOutdatedArchives_PurgesCorrectTemporaryArchives_AndRangeArchives_WhileKeepingNewerTemporaryArchives_WithBrowserTriggeringDisabled() + public function test_purgeOutdatedArchives_PurgesCorrectTemporaryArchives_WhileKeepingNewerTemporaryArchives_WithBrowserTriggeringDisabled() { $this->disableBrowserTriggeredArchiving(); $this->archivePurger->purgeOutdatedArchives($this->february); self::$fixture->assertTemporaryArchivesPurged($browserTriggeringEnabled = false, $this->february); - self::$fixture->assertCustomRangesPurged($this->february); + self::$fixture->assertCustomRangesNotPurged($this->february); self::$fixture->assertTemporaryArchivesNotPurged($this->january); } @@ -90,6 +90,14 @@ class PurgerTest extends IntegrationTestCase self::$fixture->assertInvalidatedArchivesNotPurged($this->january); } + public function test_purgeArchivesWithPeriodRange_PurgesAllRangeArchives() + { + $this->archivePurger->purgeArchivesWithPeriodRange($this->february); + + self::$fixture->assertCustomRangesPurged($this->february); + self::$fixture->assertCustomRangesNotPurged($this->january); + } + private function configureCustomRangePurging() { Config::getInstance()->General['purge_date_range_archives_after_X_days'] = 3; |