Skip to content

Commit

Permalink
[TM-1400] Update "restored" collections to "historical-tree-species"
Browse files Browse the repository at this point in the history
  • Loading branch information
roguenet committed Nov 26, 2024
1 parent 9b16f76 commit be70f3b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function parseHeaders(array $headerRow): void

$this->assert(
count(self::COLUMN_MAPPING) === count($this->columns),
"Not all required columns were found"
'Not all required columns were found'
);
}
}
31 changes: 31 additions & 0 deletions app/Console/Commands/OneOff/UpdateTreeCollections.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Console\Commands\OneOff;

use App\Models\V2\TreeSpecies\TreeSpecies;
use Illuminate\Console\Command;

class UpdateTreeCollections extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'one-off:update-tree-collections';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Removes old / missing collection names and updates to a correct value.';

/**
* Execute the console command.
*/
public function handle()
{
TreeSpecies::where('collection', 'restored')->update(['collection' => TreeSpecies::COLLECTION_HISTORICAL]);
}
}
3 changes: 1 addition & 2 deletions app/Http/Resources/V2/Organisation/OrganisationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public function toArray($request)
'founding_date' => $this->founding_date,
'description' => $this->description,

'tree_species' => TreeSpeciesResource::collection($this->treeSpecies),
'tree_species_restored' => TreeSpeciesResource::collection($this->treeSpeciesRestored),
'tree_species_historical' => TreeSpeciesResource::collection($this->treeSpeciesHistorical),
'project_pitches' => ProjectPitchResource::collection($this->projectPitches),
'leadership_team' => LeadershipTeamResource::collection($this->leadershipTeam),
'core_team_leaders' => CoreTeamLeaderResource::collection($this->coreTeamLeaders),
Expand Down
10 changes: 2 additions & 8 deletions app/Models/V2/Organisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,10 @@ public static function search($query)
->where('organisations.name', 'like', "%$query%");
}

public function treeSpecies(): MorphMany
public function treeSpeciesHistorical(): MorphMany
{
return $this->morphMany(TreeSpecies::class, 'speciesable')
->whereNull('collection');
}

public function treeSpeciesRestored(): MorphMany
{
return $this->morphMany(TreeSpecies::class, 'speciesable')
->where('collection', TreeSpecies::COLLECTION_RESTORED);
->where('collection', TreeSpecies::COLLECTION_HISTORICAL);
}

public function owners(): HasMany
Expand Down
4 changes: 2 additions & 2 deletions app/Models/V2/TreeSpecies/TreeSpecies.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ class TreeSpecies extends Model implements EntityRelationModel
public const COLLECTION_PLANTED = 'tree-planted';
public const COLLECTION_NON_TREE = 'non-tree';
public const COLLECTION_NURSERY = 'nursery-seedling';
public const COLLECTION_RESTORED = 'restored';
public const COLLECTION_HISTORICAL = 'historical-tree-species';
public const COLLECTION_PRIMARY = 'primary';

public static $collections = [
self::COLLECTION_DIRECT_SEEDING => 'Direct Seeding',
self::COLLECTION_PLANTED => 'Planted',
self::COLLECTION_NON_TREE => 'Non Tree',
self::COLLECTION_NURSERY => 'Nursery Seedling',
self::COLLECTION_RESTORED => 'Restored',
self::COLLECTION_HISTORICAL => 'Historical Tree Species',
self::COLLECTION_PRIMARY => 'Primary',
];

Expand Down
4 changes: 2 additions & 2 deletions config/wri/linked-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@
'input_type' => 'coreTeamLeaders',
],
'org-tree-species-restored' => [
'property' => 'treeSpeciesRestored',
'property' => 'treeSpeciesHistorical',
'label' => 'Tree species restored in landscape',
'resource' => 'App\Http\Resources\V2\TreeSpecies\TreeSpeciesResource',
'input_type' => 'treeSpecies',
'collection' => 'restored'
'collection' => 'historical-tree-species'
],
'org-ownership-stake' => [
'property' => 'ownershipStake',
Expand Down

0 comments on commit be70f3b

Please sign in to comment.