-
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 pull request #565 from wri/release/sassy-sycamore
[RELEASE] Sassy Sycamore
- Loading branch information
Showing
120 changed files
with
6,290 additions
and
3,582 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.'); | ||
} | ||
} |
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,71 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
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\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
class BulkApproveProjects extends Command | ||
{ | ||
protected $signature = 'bulk-approve-projects {file}'; | ||
|
||
protected $description = 'Bulk approve projects from a CSV file'; | ||
|
||
public function handle(): void | ||
{ | ||
$filePath = $this->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!"); | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\V2\Sites\SiteReport; | ||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
class BulkUpdateSiteReportDates extends Command | ||
{ | ||
protected $signature = 'sitereports:bulk-update-dates {file}'; | ||
|
||
protected $description = 'Bulk update site report due dates from a CSV file'; | ||
|
||
public function handle(): void | ||
{ | ||
$filePath = $this->argument('file'); | ||
if (! File::exists($filePath)) { | ||
$this->error("CSV file not found at {$filePath}"); | ||
|
||
return; | ||
} | ||
|
||
$output = new ConsoleOutput(); | ||
$progressBar = new ProgressBar($output); | ||
$progressBar->setFormat('Processing: %current% [%bar%] %percent:3s%%'); | ||
$progressBar->start(); | ||
|
||
$handle = fopen($filePath, 'r'); | ||
$header = fgetcsv($handle); | ||
|
||
while (($row = fgetcsv($handle)) !== false) { | ||
if (empty(array_filter($row))) { | ||
continue; | ||
} | ||
$uuid = $row[1]; | ||
$dueDateString = $row[2]; | ||
$dueDate = $this->parseDateString($dueDateString); | ||
$siteReport = SiteReport::where('uuid', $uuid)->first(); | ||
if ($siteReport) { | ||
$siteReport->update(['due_at' => $dueDate]); | ||
} | ||
|
||
$progressBar->advance(); | ||
} | ||
|
||
fclose($handle); | ||
$progressBar->finish(); | ||
$output->writeln("\nUpdate complete!"); | ||
} | ||
|
||
protected function parseDateString(string $dateString): ?Carbon | ||
{ | ||
$formats = [ | ||
'n/j/Y H:i', | ||
'n/j/Y H:i:s', | ||
'Y-m-d H:i:s', | ||
'Y-m-d', | ||
]; | ||
|
||
foreach ($formats as $format) { | ||
try { | ||
return Carbon::createFromFormat($format, $dateString)->setTimezone('UTC'); | ||
} catch (\Exception $e) { | ||
// Ignore the exception and try the next format | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
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
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
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
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,36 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\SendDailyDigestNotificationsJob; | ||
use App\Models\V2\Tasks\Task; | ||
use Illuminate\Console\Command; | ||
|
||
class SendDailyDigestNotifications extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'send-daily-digest-notifications'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Runs daily digest notifications for tasks'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
Task::isIncomplete()->chunkById(100, function ($tasks) { | ||
$tasks->each(function (Task $task) { | ||
SendDailyDigestNotificationsJob::dispatchSync($task); | ||
}); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.