-
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 #531 from wri/release/rare-redwood
[RELEASE] Rare Redwood
- Loading branch information
Showing
42 changed files
with
2,078 additions
and
248 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,61 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\V2\PolygonGeometry; | ||
use App\Models\V2\Sites\SitePolygon; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class DeleteDummyBufferedPolygons extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'delete:dummy-buffered-polygons {siteId : The UUID of the site to delete polygons for}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Delete dummy buffered polygons for a specified site'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
$siteId = $this->argument('siteId'); | ||
|
||
DB::beginTransaction(); | ||
|
||
try { | ||
|
||
$sitePolygons = SitePolygon::where('site_id', $siteId)->get(); | ||
|
||
foreach ($sitePolygons as $sitePolygon) { | ||
$polygonGeometry = PolygonGeometry::where('uuid', $sitePolygon->poly_id)->first(); | ||
if ($polygonGeometry) { | ||
$polygonGeometry->deleteWithRelated(); | ||
} | ||
} | ||
|
||
DB::commit(); | ||
|
||
$this->info("Dummy buffered polygons for site ID $siteId have been successfully deleted."); | ||
|
||
} catch (\Exception $e) { | ||
DB::rollBack(); | ||
$this->error('Failed to delete dummy buffered polygons: ' . $e->getMessage()); | ||
|
||
return Command::FAILURE; | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
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
110 changes: 110 additions & 0 deletions
110
app/Console/Commands/OneOff/GenerateBackDatedReportsEnterprisesCommand.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,110 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\OneOff; | ||
|
||
use App\Models\V2\Action; | ||
use App\Models\V2\Projects\Project; | ||
use App\Models\V2\Projects\ProjectReport; | ||
use App\Models\V2\Tasks\Task; | ||
use App\StateMachines\ReportStatusStateMachine; | ||
use App\StateMachines\TaskStatusStateMachine; | ||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
|
||
class GenerateBackDatedReportsEnterprisesCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'one-off:generate-backdated-reports-enterprises-command'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Generates backdated reports for enterprises framework'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$due_at = Carbon::createFromFormat('m', 7)->startOfMonth()->setDay(30)->setHours(5); | ||
$period_key = $due_at->year . '-' . $due_at->month; | ||
$framework_key = 'enterprises'; | ||
Project::where('framework_key', $framework_key) | ||
->chunkById(100, function ($projects) use ($framework_key, $period_key, $due_at) { | ||
foreach ($projects as $project) { | ||
$this->createTask($project, $framework_key, $period_key, $due_at); | ||
} | ||
}); | ||
} | ||
|
||
public function createTask($project, $framework_key, $period_key, $due_at) | ||
{ | ||
$task = Task::create([ | ||
'organisation_id' => $project->organisation_id, | ||
'project_id' => $project->id, | ||
'status' => TaskStatusStateMachine::DUE, | ||
'period_key' => $period_key, | ||
'due_at' => $due_at, | ||
]); | ||
|
||
$projectReport = $task->projectReport()->create([ | ||
'framework_key' => $framework_key, | ||
'project_id' => $project->id, | ||
'status' => ReportStatusStateMachine::DUE, | ||
'due_at' => $due_at, | ||
]); | ||
|
||
$hasSite = false; | ||
foreach ($project->sites as $site) { | ||
$hasSite = true; | ||
$task->siteReports()->create([ | ||
'framework_key' => $framework_key, | ||
'site_id' => $site->id, | ||
'status' => ReportStatusStateMachine::DUE, | ||
'due_at' => $due_at, | ||
]); | ||
} | ||
|
||
$hasNursery = false; | ||
foreach ($project->nurseries as $nursery) { | ||
$hasNursery = true; | ||
$task->nurseryReports()->create([ | ||
'framework_key' => $framework_key, | ||
'nursery_id' => $nursery->id, | ||
'status' => ReportStatusStateMachine::DUE, | ||
'due_at' => $due_at, | ||
]); | ||
} | ||
|
||
$labels = ['Project']; | ||
if ($hasSite) { | ||
$labels[] = 'site'; | ||
} | ||
if ($hasNursery) { | ||
$labels[] = 'nursery'; | ||
} | ||
$message = printf( | ||
'%s %s available', | ||
implode(', ', $labels), | ||
count($labels) > 1 ? 'reports' : 'report' | ||
); | ||
|
||
Action::create([ | ||
'status' => Action::STATUS_PENDING, | ||
'targetable_type' => ProjectReport::class, | ||
'targetable_id' => $projectReport->id, | ||
'type' => Action::TYPE_NOTIFICATION, | ||
'title' => 'Project report', | ||
'sub_title' => '', | ||
'text' => $message, | ||
'project_id' => $project->id, | ||
'organisation_id' => $project->organisation_id, | ||
]); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/Console/Commands/OneOff/SeedScheduledJobsHbfEnterprisesCommand.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,59 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\OneOff; | ||
|
||
use App\Models\V2\ScheduledJobs\TaskDueJob; | ||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
|
||
class SeedScheduledJobsHbfEnterprisesCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'one-off:seed-scheduled-jobs-hbf-enterprises'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Creates the initial definition of scheduled jobs for hbf and enterprises frameworks'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
// HBF reports | ||
// May-October, November 1, December 1 | ||
TaskDueJob::createTaskDue( | ||
Carbon::createFromFormat('m', 11)->startOfMonth()->setDay(1), | ||
'hbf', | ||
Carbon::createFromFormat('m', 12)->startOfMonth()->setDay(1)->setHours(5), | ||
); | ||
// November-April, May 1, June 1 | ||
TaskDueJob::createTaskDue( | ||
Carbon::createFromFormat('m', 5)->startOfMonth()->setDay(1), | ||
'hbf', | ||
Carbon::createFromFormat('m', 6)->startOfMonth()->setDay(3)->setHours(5), | ||
); | ||
|
||
// Enterprises reports | ||
// January-June, July 1, July 30 | ||
TaskDueJob::createTaskDue( | ||
Carbon::createFromFormat('m', 7)->startOfMonth()->setDay(1), | ||
'enterprises', | ||
Carbon::createFromFormat('m', 7)->startOfMonth()->setDay(30)->setHours(5), | ||
); | ||
// July-December, January 1, January 30 | ||
TaskDueJob::createTaskDue( | ||
Carbon::createFromFormat('m', 1)->startOfMonth()->setDay(1), | ||
'enterprises', | ||
Carbon::createFromFormat('m', 1)->startOfMonth()->setDay(30)->setHours(5), | ||
); | ||
|
||
} | ||
} |
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
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
21 changes: 21 additions & 0 deletions
21
app/Http/Controllers/V2/Exports/GeneratePreSignedURLDownloadReportController.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,21 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V2\Exports; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class GeneratePreSignedURLDownloadReportController extends Controller | ||
{ | ||
public function __invoke(Request $request, string $entity, string $framework) | ||
{ | ||
$fileKey = 'exports/all-entity-records/'.$entity.'-'.$framework.'.csv'; | ||
|
||
$expiration = now()->addMinutes(60); | ||
|
||
$presignedUrl = Storage::disk('s3')->temporaryUrl($fileKey, $expiration); | ||
|
||
return response()->json(['url' => $presignedUrl]); | ||
} | ||
} |
Oops, something went wrong.