From 9aee02dfc45f961e8cce5ad062724dc3a7e9ccc1 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Mon, 20 Apr 2020 19:33:18 -0700 Subject: Always purge today & yesterday and add update for 3.13.5 (#15832) * Always purge today/yesterday when running invalidated archive purge task and add update to add all tables to purge for next version. * Add some comments. * Only add dates if they are past 2020-03. * Only add tables above 2020-01. --- core/Updates/3.13.5-rc1.php | 45 +++++++++++++++++++++++++++++++++++++++++ core/Version.php | 2 +- plugins/CoreAdminHome/Tasks.php | 19 +++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 core/Updates/3.13.5-rc1.php diff --git a/core/Updates/3.13.5-rc1.php b/core/Updates/3.13.5-rc1.php new file mode 100644 index 0000000000..d465c31683 --- /dev/null +++ b/core/Updates/3.13.5-rc1.php @@ -0,0 +1,45 @@ +addArchivesToPurge(); + } + + private function addArchivesToPurge() + { + $archivesToPurge = new ArchivesToPurgeDistributedList(); + + $startOfProblem = Date::factory('2020-01-01 00:00:00'); + + $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled(ArchiveTableCreator::NUMERIC_TABLE); + foreach ($archiveTables as $table) { + $date = ArchiveTableCreator::getDateFromTableName($table); + list($year, $month) = explode('_', $date); + + // only add if the table is for jan 2020 or above since tables w/ that date will be most affected + $dateObj = Date::factory("$year-$month-01 00:00:00"); + if ($dateObj->isEarlier($startOfProblem)) { + continue; + } + + $archivesToPurge->add("{$year}_{$month}"); + } + } +} \ No newline at end of file diff --git a/core/Version.php b/core/Version.php index d04c036558..fc0bcae937 100644 --- a/core/Version.php +++ b/core/Version.php @@ -20,7 +20,7 @@ final class Version * The current Matomo version. * @var string */ - const VERSION = '3.13.5-b2'; + const VERSION = '3.13.5-rc1'; public function isStableVersion($version) { diff --git a/plugins/CoreAdminHome/Tasks.php b/plugins/CoreAdminHome/Tasks.php index ad81187aa8..ff3ae6497f 100644 --- a/plugins/CoreAdminHome/Tasks.php +++ b/plugins/CoreAdminHome/Tasks.php @@ -252,11 +252,30 @@ class Tasks extends \Piwik\Plugin\Tasks public function purgeInvalidatedArchives() { + $purgedDates = []; + $archivesToPurge = new ArchivesToPurgeDistributedList(); foreach ($archivesToPurge->getAllAsDates() as $date) { $this->archivePurger->purgeInvalidatedArchivesFrom($date); $archivesToPurge->removeDate($date); + + $purgedDates[$date->toString('Y-m')] = true; + } + + // purge from today if not done already since we will have many archives to remove + $today = Date::today(); + $todayStr = $today->toString('Y-m'); + if (empty($purgedDates[$todayStr])) { + $this->archivePurger->purgeInvalidatedArchivesFrom($today); + $purgedDates[$todayStr] = true; + } + + // handle yesterday if it belongs to a different month + $yesterday = Date::yesterday(); + $yesterdayStr = $yesterday->toString('Y-m'); + if (empty($purgedDates[$yesterdayStr])) { + $this->archivePurger->purgeInvalidatedArchivesFrom($yesterday); } } -- cgit v1.2.3