From 51532287585801ed137ab40b4156e2ce071c3f4b Mon Sep 17 00:00:00 2001 From: guillaume91 Date: Tue, 18 Jun 2024 16:31:35 +0200 Subject: [PATCH] Changed GetFileDownloadsFor and all the functions called inside --- laravel_app/app/Models/Project.php | 10 ++++------ laravel_app/tests/Unit/Models/ProjectTest.php | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/laravel_app/app/Models/Project.php b/laravel_app/app/Models/Project.php index 7767904..f9f5452 100644 --- a/laravel_app/app/Models/Project.php +++ b/laravel_app/app/Models/Project.php @@ -319,7 +319,7 @@ public function scheduleReport($year = null, $week = null) $year = $year ?? now()->year; $week = $week ?? now()->weekOfYear; - + // TODO change to period Bus::chain([ Bus::batch($this->getFileDownloadsFor($year, $week)), Bus::batch($this->getMosaicsFor($year, $week)), @@ -341,12 +341,10 @@ public function getReportFor($year, $week, $sendMail = false) return (new ProjectReportGeneratorJob($report, $sendMail)); } - public function getFileDownloadsFor($year, $startWeekNumber):array + public function getFileDownloadsFor(Carbon $endDate, $offset):array { - $endOfRange = now()->setISODate($year, $startWeekNumber)->endOfWeek(); - $startOfRange = (clone $endOfRange)->subWeeks(3)->startOfWeek(); - - $dateRange = CarbonPeriod::create($startOfRange, $endOfRange); + $startOfRange = (clone $endDate)->subdays(4*$offset-1); + $dateRange = CarbonPeriod::create($startOfRange, $endDate); return collect($dateRange) ->map(fn($date) => ProjectDownloadTiffJob::handleForDate($this, $date)) diff --git a/laravel_app/tests/Unit/Models/ProjectTest.php b/laravel_app/tests/Unit/Models/ProjectTest.php index 5734ecb..567c9c3 100644 --- a/laravel_app/tests/Unit/Models/ProjectTest.php +++ b/laravel_app/tests/Unit/Models/ProjectTest.php @@ -162,8 +162,8 @@ public function when_getFileDownloadsFor_is_called_it_returns_a_collection_of_se 'download_path' => 'project_download_path', ]); - $downloads = $project->getFileDownloadsFor(2023, 22); - $this->assertCount(4 * 7, $downloads); + $downloads = $project->getFileDownloadsFor(new Carbon('2024-06-18'),20); + $this->assertCount(60, $downloads); collect($downloads)->each(fn($job) => $this->assertInstanceOf(ProjectDownloadTiffJob::class, $job)); }