-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/TM-1386-bulk-approved' of https://github.com/wri/w…
…ri-terramatch-api into feat/TM-1386-bulk-approved
- Loading branch information
Showing
3 changed files
with
402 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Database\Seeders; | ||
|
||
use App\Models\V2\Projects\Project; | ||
use App\Models\V2\Projects\ProjectReport; | ||
use App\Models\V2\Sites\SiteReport; | ||
use App\Models\V2\Tasks\Task; | ||
use Illuminate\Database\Seeder; | ||
use Illuminate\Support\Facades\File; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
class UpdateProjectStatusSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
*/ | ||
public function run() | ||
{ | ||
$filePath = __DIR__ . '/../../resources/seeds/bulk_approve_projects.csv'; | ||
|
||
if (! File::exists($filePath)) { | ||
$this->command->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(); | ||
|
||
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']) | ||
->update(['status' => 'approved']); | ||
|
||
$sites = $project->sites; | ||
foreach ($sites as $site) { | ||
SiteReport::where('site_id', $site->id) | ||
->whereIn('status', ['awaiting-approval', 'needs-more-information']) | ||
->update(['status' => 'approved']); | ||
} | ||
|
||
Task::where('project_id', $project->id) | ||
->whereIn('status', ['awaiting-approval', 'needs-more-information']) | ||
->update(['status' => 'approved']); | ||
} | ||
|
||
$progressBar->advance(); | ||
} | ||
|
||
$progressBar->finish(); | ||
$output->writeln("\nUpdate complete!"); | ||
} | ||
} |
Oops, something went wrong.