-
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.
[TM-1471] command to approve polygons (#567)
* [TM-1471] command to approve polygons * [TM-1471] add lint
- Loading branch information
1 parent
9e63a7f
commit 537c436
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
app/Console/Commands/BulkApproveProjectPolygonsCommand.php
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,67 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Traits\SaveAuditStatusTrait; | ||
use App\Models\V2\Projects\Project; | ||
use App\Models\V2\User; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\File; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
class BulkApproveProjectPolygonsCommand extends Command | ||
{ | ||
use SaveAuditStatusTrait; | ||
|
||
protected $signature = 'bulk-approve-project-polygons {file}'; | ||
|
||
protected $description = 'Bulk approve site polygons for projects listed in a CSV file'; | ||
|
||
public function handle(): void | ||
{ | ||
$filePath = $this->argument('file'); | ||
|
||
if (! File::exists($filePath)) { | ||
$this->error("CSV file not found at {$filePath}"); | ||
|
||
return; | ||
} | ||
$userEmail = '[email protected]'; | ||
$user = User::where('email_address', $userEmail)->first(); | ||
Auth::login($user); | ||
$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(); | ||
|
||
$polygonsChanged = []; | ||
|
||
foreach ($data as $row) { | ||
$uuid = $row[0]; | ||
$project = Project::isUuid($uuid)->first(); | ||
$this->info("\nProcessing project " . $uuid); | ||
if ($project) { | ||
foreach ($project->sitePolygons as $sitePolygon) { | ||
$sitePolygon->status = 'approved'; | ||
$sitePolygon->save(); | ||
|
||
$this->saveAuditStatus(get_class($sitePolygon), $sitePolygon->id, $sitePolygon->status, 'Approved via bulk command', 'status'); | ||
|
||
$polygonsChanged[] = $sitePolygon; | ||
} | ||
} | ||
|
||
$progressBar->advance(); | ||
} | ||
|
||
$progressBar->finish(); | ||
|
||
// Print summary of the number of polygons approved | ||
$this->info("\n" . count($polygonsChanged) . ' polygons were updated.'); | ||
} | ||
} |