fetch moon observer job

This commit is contained in:
2020-05-27 02:49:39 -05:00
parent 7ea6735167
commit 5f3639e945
2 changed files with 17 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ use Log;
use Seat\Eseye\Exceptions\RequestFailedException; use Seat\Eseye\Exceptions\RequestFailedException;
use App\Library\Esi\Esi; use App\Library\Esi\Esi;
use App\Library\Lookups\LookupHelper; use App\Library\Lookups\LookupHelper;
use App\Library\Structures\StructureHelper;
//App Models //App Models
use App\Models\Moon\CorpMoonObserver; use App\Models\Moon\CorpMoonObserver;
@@ -78,6 +79,11 @@ class FetchMoonObserverJob implements ShouldQueue
//With the lookup helper, get the character information //With the lookup helper, get the character information
$character = $lookup->GetCharacterInfo($this->charId); $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 //Get the mining observers for the corporation's from esi
try { try {
@@ -93,8 +99,16 @@ class FetchMoonObserverJob implements ShouldQueue
$count = CorpMoonObserver::where(['observer_id' => $observer->observer_id])->count(); $count = CorpMoonObserver::where(['observer_id' => $observer->observer_id])->count();
//If the observer is not found, then add it to the database //If the observer is not found, then add it to the database
if($count == 0) { 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 = new CorpMoonObserver;
$obs->corporation_id = $character->corporation_id;
$obs->corporation_name = $corporation->name;
$obs->observer_id = $observer->observer_id; $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->observer_type = $observer->observer_type;
$obs->last_updated = $observer->last_updated; $obs->last_updated = $observer->last_updated;
$obs->save(); $obs->save();

View File

@@ -51,8 +51,8 @@ class CreateRentalMoonLedgerTables extends Migration
$table->unsignedBigInteger('corporation_id'); $table->unsignedBigInteger('corporation_id');
$table->string('corporation_name'); $table->string('corporation_name');
$table->unsignedBigInteger('observer_id'); $table->unsignedBigInteger('observer_id');
$table->string('observer_name'); $table->string('observer_name')->nullable();
$table->string('observer_type'); $table->string('observer_type')->nullable();
$table->unsignedBigInteger('observer_owner_id'); $table->unsignedBigInteger('observer_owner_id');
$table->unsignedBigInteger('solar_system_id'); $table->unsignedBigInteger('solar_system_id');
$table->unsignedBigInteger('observer_type_id'); $table->unsignedBigInteger('observer_type_id');