From 5f3639e9450e0fad91cfe28c0da7785c56f3c8b3 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Wed, 27 May 2020 02:49:39 -0500 Subject: [PATCH] fetch moon observer job --- app/Jobs/Commands/Moons/FetchMoonObserverJob.php | 16 +++++++++++++++- ...7_033014_create_rental_moon_ledger_tables.php | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/Jobs/Commands/Moons/FetchMoonObserverJob.php b/app/Jobs/Commands/Moons/FetchMoonObserverJob.php index e19c5bc4d..af4f1a360 100644 --- a/app/Jobs/Commands/Moons/FetchMoonObserverJob.php +++ b/app/Jobs/Commands/Moons/FetchMoonObserverJob.php @@ -14,6 +14,7 @@ use Log; use Seat\Eseye\Exceptions\RequestFailedException; use App\Library\Esi\Esi; use App\Library\Lookups\LookupHelper; +use App\Library\Structures\StructureHelper; //App Models use App\Models\Moon\CorpMoonObserver; @@ -74,10 +75,15 @@ class FetchMoonObserverJob implements ShouldQueue //Get the refresh token for the character $refreshToken = $esiHelper->GetRefreshToken($this->charId); //Get the esi variable - $esi = $esiHelper->SetupEsiAuthentication($refreshToken); + $esi = $esiHelper->SetupEsiAuthentication($refreshToken); //With the lookup helper, get the character information $character = $lookup->GetCharacterInfo($this->charId); + //With the lookup helper, get the corporation information + $corporation = $lookup->GetCorporationInfo($character->corporation_id); + + //Delcare the structure helper since we have the necessary data + $structureHelper = new Structure($this->charId, $character->corporation_id, $esi); //Get the mining observers for the corporation's from esi try { @@ -93,8 +99,16 @@ class FetchMoonObserverJob implements ShouldQueue $count = CorpMoonObserver::where(['observer_id' => $observer->observer_id])->count(); //If the observer is not found, then add it to the database if($count == 0) { + //Get the structure information from the universe structure esi endpoint + $structureInfo = $structureHelper->GetStructureInfo($observer->observer_id); + //Create a new corp moon observer in the database $obs = new CorpMoonObserver; + $obs->corporation_id = $character->corporation_id; + $obs->corporation_name = $corporation->name; $obs->observer_id = $observer->observer_id; + $obs->observer_name = $structureInfo->name; + $obs->observer_owner_id = $structureInfo->owner_id; + $obs->solar_system_id = $structureInfo->solar_system_id; $obs->observer_type = $observer->observer_type; $obs->last_updated = $observer->last_updated; $obs->save(); diff --git a/database/migrations/2020_05_07_033014_create_rental_moon_ledger_tables.php b/database/migrations/2020_05_07_033014_create_rental_moon_ledger_tables.php index f0138f201..b7bbd9a01 100644 --- a/database/migrations/2020_05_07_033014_create_rental_moon_ledger_tables.php +++ b/database/migrations/2020_05_07_033014_create_rental_moon_ledger_tables.php @@ -51,8 +51,8 @@ class CreateRentalMoonLedgerTables extends Migration $table->unsignedBigInteger('corporation_id'); $table->string('corporation_name'); $table->unsignedBigInteger('observer_id'); - $table->string('observer_name'); - $table->string('observer_type'); + $table->string('observer_name')->nullable(); + $table->string('observer_type')->nullable(); $table->unsignedBigInteger('observer_owner_id'); $table->unsignedBigInteger('solar_system_id'); $table->unsignedBigInteger('observer_type_id');