Skip to content

Commit

Permalink
Merge pull request #78 from wri/release/booming-baobab
Browse files Browse the repository at this point in the history
[RELEASE] Booming Baobab
  • Loading branch information
roguenet authored Mar 8, 2024
2 parents 0f12783 + eb41622 commit 0fbc87b
Show file tree
Hide file tree
Showing 174 changed files with 3,184 additions and 3,573 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ build:
docker-compose run php php ./artisan jwt:secret
docker-compose run npm npm run development

composer:
docker-compose run composer composer install --ignore-platform-reqs

up:
docker-compose up -d

Expand Down
83 changes: 83 additions & 0 deletions app/Console/Commands/CreateBackdatedReportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace App\Console\Commands;

use App\Models\V2\Nurseries\Nursery;
use App\Models\V2\Nurseries\NurseryReport;
use App\Models\V2\Sites\Site;
use App\Models\V2\Sites\SiteReport;
use App\Models\V2\Tasks\Task;
use Carbon\Carbon;
use Illuminate\Console\Command;

class CreateBackdatedReportCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'create-backdated-report {--T|type=} {uuid}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a report for a specific site or nursery';

public function handle(): int
{
$type = $this->option('type');
switch ($type) {
case 'site':
$entityModel = Site::class;
$reportModel = SiteReport::class;
break;

case 'nursery':
$entityModel = Nursery::class;
$reportModel = NurseryReport::class;
break;

default:
$this->error('Type must be one of "site" or "nursery"');
return 1;
}

$uuid = $this->argument('uuid');

$entity = $entityModel::where('uuid', $uuid)->first();
if ($entity == null) {
$this->error("Entity.php not found [type=$type, uuid=$uuid]");
return 1;
}

$task = Task::withTrashed()->where('project_id', $entity->project_id)->latest()->first();
if ($task == null) {
$this->error("Task not found for project [$entity->project_id]");
return 1;
}

if ($task->trashed()) {
$task->restore();
$this->info("Task restored [task=$task->id, project=$task->project_id]");
}
if ($task->status !== 'due') {
$task->update(['status' => 'due']);
$this->info("Task status updated to 'due' [task=$task->id, project=$task->project_id]");
}

$reportModel::create([
'framework_key' => $task->project->framework_key,
'task_id' => $task->id,
"{$type}_id" => $entity->id,
'status' => 'due',
'due_at' => $task->due_at,
]);

$this->info("Report created for $type $uuid");

return 0;
}
}
69 changes: 0 additions & 69 deletions app/Console/Commands/CreateSpecificSiteReportCommand.php

This file was deleted.

64 changes: 0 additions & 64 deletions app/Console/Commands/FixReportCompletion.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use App\Models\V2\Sites\SiteReport;
use App\Models\V2\Tasks\Task;
use App\Models\V2\UpdateRequests\UpdateRequest;
use App\StateMachines\ReportStatusStateMachine;
use App\StateMachines\TaskStatusStateMachine;
use Illuminate\Console\Command;

class CreateDueReportsMigrationCommand extends Command
Expand Down Expand Up @@ -62,7 +64,7 @@ private function handleTerrafundStubs()
$report = ProjectReport::updateOrCreate([
'framework_key' => 'terrafund',
'project_id' => $project->id,
'status' => ProjectReport::STATUS_DUE,
'status' => ReportStatusStateMachine::DUE,
'due_at' => $stub->due_at,
], []);

Expand All @@ -80,7 +82,7 @@ private function handleTerrafundStubs()
$report = SiteReport::updateOrCreate([
'framework_key' => 'terrafund',
'site_id' => $site->id,
'status' => SiteReport::STATUS_DUE,
'status' => ReportStatusStateMachine::DUE,
'due_at' => $stub->due_at,
], []);

Expand All @@ -98,7 +100,7 @@ private function handleTerrafundStubs()
$report = NurseryReport::updateOrCreate([
'framework_key' => 'terrafund',
'nursery_id' => $nursery->id,
'status' => SiteReport::STATUS_DUE,
'status' => ReportStatusStateMachine::DUE,
'due_at' => $stub->due_at,
], []);

Expand Down Expand Up @@ -126,7 +128,7 @@ private function handlePPCStubs()
$report = ProjectReport::updateOrCreate([
'framework_key' => 'ppc',
'project_id' => $project->id,
'status' => ProjectReport::STATUS_DUE,
'status' => ReportStatusStateMachine::DUE,
'due_at' => $stub->due_at,
], []);

Expand All @@ -144,7 +146,7 @@ private function handlePPCStubs()
$report = SiteReport::updateOrCreate([
'framework_key' => 'ppc',
'site_id' => $site->id,
'status' => SiteReport::STATUS_DUE,
'status' => ReportStatusStateMachine::DUE,
'due_at' => $stub->due_at,
], []);

Expand Down Expand Up @@ -195,7 +197,7 @@ private function handleTask($project, $stub)
'period_key' => $stub->due_at->year . '-' . ($stub->due_at->month < 10 ? '0'. $stub->due_at->month : $stub->due_at->month),
],
[
'status' => Task::STATUS_DUE,
'status' => TaskStatusStateMachine::DUE,
'due_at' => $stub->due_at,
]
);
Expand All @@ -221,7 +223,7 @@ private function handleParentActions($item)
$report = ProjectReport::create([
'framework_key' => $project->faramework_key,
'project_id' => $project->id,
'status' => ProjectReport::STATUS_DUE,
'status' => ReportStatusStateMachine::DUE,
'due_at' => $item->due_at,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\V2\Projects\Project;
use App\Models\V2\Projects\ProjectReport;
use App\Models\V2\Tasks\Task;
use App\StateMachines\TaskStatusStateMachine;
use Illuminate\Console\Command;

class CreateTasksMigrationCommand extends Command
Expand Down Expand Up @@ -51,7 +52,7 @@ public function handle()
$map = [
'organisation_id' => $project->organisation_id,
'project_id' => $project->id,
'status' => Task::STATUS_COMPLETE,
'status' => $report->status,
'period_key' => $item['year'] . '-' . ($item['month'] < 10 ? '0'. $item['month'] : $item['month']),
'due_at' => $report->due_at,
];
Expand All @@ -75,7 +76,7 @@ public function handle()
$map = [
'organisation_id' => $project->organisation_id,
'project_id' => $project->id,
'status' => Task::STATUS_COMPLETE,
'status' => $report->status,
'period_key' => $item['year'] . '-' . ($item['month'] < 10 ? '0' . $item['month'] : $item['month']),
'due_at' => $report->created_at,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Models\Terrafund\TerrafundProgramme;
use App\Models\V2\Nurseries\Nursery;
use App\Models\V2\Projects\Project;
use App\Models\V2\Sites\Site;
use App\StateMachines\EntityStatusStateMachine;
use Illuminate\Console\Command;

class NurseryTerrafundMigrationCommand extends Command
Expand Down Expand Up @@ -65,7 +65,7 @@ private function mapValues(TerrafundNursery $nursery): array
'name' => data_get($nursery, 'name'),
'start_date' => data_get($nursery, 'start_date'),
'end_date' => data_get($nursery, 'end_date'),
'status' => Site::STATUS_APPROVED,
'status' => EntityStatusStateMachine::APPROVED,
'seedling_grown' => data_get($nursery, 'seedling_grown'),
'planting_contribution' => data_get($nursery, 'planting_contribution'),
'type' => data_get($nursery, 'nursery_type'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Programme;
use App\Models\V2\Projects\Project;
use App\StateMachines\EntityStatusStateMachine;
use Illuminate\Console\Command;

class ProjectPPCMigrationCommand extends Command
Expand Down Expand Up @@ -60,7 +61,7 @@ private function mapValues(Programme $programme): array
'framework_key' => 'ppc',

'name' => data_get($programme, 'name'),
'status' => Project::STATUS_APPROVED,
'status' => EntityStatusStateMachine::APPROVED,
'organisation_id' => data_get($programme, 'organisation_id'),
'boundary_geojson' => data_get($programme, 'boundary_geojson'),
'country' => data_get($programme, 'country'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Terrafund\TerrafundProgramme;
use App\Models\V2\Projects\Project;
use App\StateMachines\EntityStatusStateMachine;
use Illuminate\Console\Command;

class ProjectTerrafundMigrationCommand extends Command
Expand Down Expand Up @@ -60,7 +61,7 @@ private function mapValues(TerrafundProgramme $programme): array
'organisation_id' => data_get($programme, 'organisation_id'),

'name' => data_get($programme, 'name'),
'status' => Project::STATUS_APPROVED,
'status' => EntityStatusStateMachine::APPROVED,
'project_status' => data_get($programme, 'status'),
'boundary_geojson' => data_get($programme, 'boundary_geojson'),
'country' => data_get($programme, 'project_country'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Terrafund\TerrafundNurserySubmission;
use App\Models\V2\Nurseries\Nursery;
use App\Models\V2\Nurseries\NurseryReport;
use App\StateMachines\ReportStatusStateMachine;
use Illuminate\Console\Command;

class ReportNurseryTerrafundMigrationCommand extends Command
Expand Down Expand Up @@ -62,7 +63,7 @@ private function mapValues(TerrafundNurserySubmission $submission): array
'framework_key' => 'terrafund',

'due_at' => $this->handleDueAt($submission),
'status' => NurseryReport::STATUS_AWAITING_APPROVAL,
'status' => ReportStatusStateMachine::AWAITING_APPROVAL,
'seedlings_young_trees' => data_get($submission, 'seedlings_young_trees'),
'interesting_facts' => data_get($submission, 'interesting_facts'),
'site_prep' => data_get($submission, 'site_prep'),
Expand Down
Loading

0 comments on commit 0fbc87b

Please sign in to comment.