From 1ef548f5a28d08f741697fd012a3c988b3e5c8a0 Mon Sep 17 00:00:00 2001 From: Ben Burgess <88810029+bx80@users.noreply.github.com> Date: Tue, 9 Aug 2022 03:16:17 +1200 Subject: Fix for current year not processed for new custom reports (#19569) * Ignore repair year invalidation when processing a week that spans two years * Added integration test * Fixed test --- core/CronArchive.php | 9 +++++++- tests/PHPUnit/Integration/CronArchiveTest.php | 31 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/core/CronArchive.php b/core/CronArchive.php index de55cddcc0..7108ef9e04 100644 --- a/core/CronArchive.php +++ b/core/CronArchive.php @@ -1054,13 +1054,20 @@ class CronArchive continue; } - // archive is for week that is over two months, we don't need to care about the month + // archive is for a week that is over two months, we don't need to care about the month if ($label == 'month' && Date::factory($archiveToProcess['date1'])->toString('m') != Date::factory($archiveToProcess['date2'])->toString('m') ) { continue; } + // archive is for a week that is over two years, we don't need to care about the year + if ($label == 'year' + && Date::factory($archiveToProcess['date1'])->toString('y') != Date::factory($archiveToProcess['date2'])->toString('y') + ) { + continue; + } + $period = Period\Factory::build($label, $archiveToProcess['date1']); $invalidationToInsert = [ diff --git a/tests/PHPUnit/Integration/CronArchiveTest.php b/tests/PHPUnit/Integration/CronArchiveTest.php index 643908b973..64a5e17dd3 100644 --- a/tests/PHPUnit/Integration/CronArchiveTest.php +++ b/tests/PHPUnit/Integration/CronArchiveTest.php @@ -300,6 +300,37 @@ class CronArchiveTest extends IntegrationTestCase ), ], ], + + // week split across two years - make sure the year invalidation isn't changed to the week start year + [ + [ + ['idarchive' => 1, 'idsite' => 1, 'period' => 2, 'date1' => '2021-12-27', 'date2' => '2022-01-02', 'name' => 'done', 'report' => null, 'ts_invalidated' => '2022-03-04 01:00:00'], + ['idarchive' => 1, 'idsite' => 1, 'period' => 4, 'date1' => '2022-01-01', 'date2' => '2022-12-31', 'name' => 'done', 'report' => null, 'ts_invalidated' => '2022-03-04 01:00:00'], + ], + ['idarchive' => 1, 'idsite' => 1, 'period' => 2, 'date1' => '2021-12-27', 'date2' => '2022-01-02', 'name' => 'done', 'report' => null, 'ts_invalidated' => '2022-03-04 01:00:00'], + [ + array ( + 'idarchive' => '1', + 'idsite' => '1', + 'period' => '2', + 'date1' => '2021-12-27', + 'date2' => '2022-01-02', + 'name' => 'done', + 'report' => NULL, + 'ts_invalidated' => '2022-03-04 01:00:00', + ), + array ( + 'idarchive' => 1, + 'idsite' => '1', + 'period' => '4', + 'date1' => '2022-01-01', + 'date2' => '2022-12-31', + 'name' => 'done', + 'report' => NULL, + 'ts_invalidated' => '2022-03-04 01:00:00', + ), + ], + ], ]; } -- cgit v1.2.3