diff --git a/app/Console/Commands/BulkApproveProjects.php b/app/Console/Commands/BulkApproveProjects.php new file mode 100644 index 000000000..9e813a695 --- /dev/null +++ b/app/Console/Commands/BulkApproveProjects.php @@ -0,0 +1,71 @@ +argument('file'); + + if (! File::exists($filePath)) { + $this->error("CSV file not found at {$filePath}"); + + return; + } + + $data = array_map('str_getcsv', file($filePath)); + $header = array_shift($data); + $output = new ConsoleOutput(); + $progressBar = new ProgressBar($output, count($data)); + $progressBar->setFormat('Processing: %current% [%bar%] %percent:3s%%'); + + $progressBar->start(); + + + $excludeDueDate = '2024-07-30'; + foreach ($data as $row) { + $uuid = $row[0]; + + $project = Project::where('uuid', $uuid)->first(); + + if ($project) { + ProjectReport::where('project_id', $project->id) + ->whereIn('status', ['awaiting-approval', 'needs-more-information']) + ->whereDate('due_at', '!=', $excludeDueDate) + ->update(['status' => 'approved']); + + $sites = $project->sites; + foreach ($sites as $site) { + SiteReport::where('site_id', $site->id) + ->whereIn('status', ['awaiting-approval', 'needs-more-information']) + ->whereDate('due_at', '!=', $excludeDueDate) + ->update(['status' => 'approved']); + } + + Task::where('project_id', $project->id) + ->whereIn('status', ['awaiting-approval', 'needs-more-information']) + ->whereDate('due_at', '!=', $excludeDueDate) + ->update(['status' => 'approved']); + } + + $progressBar->advance(); + } + + $progressBar->finish(); + $output->writeln("\nUpdate complete!"); + } +}