more work on rental moon ledgers
This commit is contained in:
@@ -10,19 +10,48 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Log;
|
||||
|
||||
//App Library
|
||||
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\CorpMoonLedger;
|
||||
use App\Models\CorpMoonObserver;
|
||||
|
||||
|
||||
class FetchMoonLedgerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Timeout in seconds
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Retries
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $retries = 3;
|
||||
|
||||
/**
|
||||
* Private Variables
|
||||
*/
|
||||
private $charId;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($charId)
|
||||
{
|
||||
//
|
||||
$this->charId = $charId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,6 +61,60 @@ class FetchMoonLedgerJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
//Declare Variables
|
||||
$esiHelper = new Esi;
|
||||
$lookup = new LookupHelper;
|
||||
$structure = new StructureHelper;
|
||||
$response = null;
|
||||
$structureInfo = null;
|
||||
|
||||
//Get the configuration for the main site
|
||||
$config = config('esi');
|
||||
|
||||
//Check for esi scope for the character
|
||||
if(!$esiHelper->HaveEsiScope($this->charId, 'esi-industry.read_corporation_mining.v1') || !$esiHelper->HaveEsiScope($this->charId, 'esi-universe.read_structures.v1')) {
|
||||
Log::critical('The primary character does not have the necessary scopes for FetchRentalMoonLedgerCommand.');
|
||||
return;
|
||||
}
|
||||
|
||||
//Get the refresh token if the scope checks have passed
|
||||
$refreshToken = $esiHelper->GetRefreshToken($this->charId);
|
||||
|
||||
//Get the character data from the lookup table
|
||||
$character = $lookup->GetCharacterInfo($this->charId);
|
||||
|
||||
//Get the corporation data from the lookup table
|
||||
$corporation = $lookup->GetCorporationInfo($character->corporation_id);
|
||||
|
||||
//Get the moon observers from the database
|
||||
$observers = CorpMoonObserver::where([
|
||||
'corporation_id' => $character->corporation_id,
|
||||
])->get();
|
||||
|
||||
foreach($observers as $observer) {
|
||||
try {
|
||||
$ledgers = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [
|
||||
'corporation_id' => $character->corporation_id,
|
||||
'observer_id' => $observer->observer_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
//Log the exception
|
||||
Log::critical('FetchMoonLedger job failed to get the mining ledgers.');
|
||||
}
|
||||
|
||||
if($ledgers != null) {
|
||||
foreach($ledgers as $ledger) {
|
||||
//Get the ore name from the lookup table
|
||||
$ore = $lookup->ItemIdToName($ledger->type_id);
|
||||
|
||||
//Get the character name from the lookup helper
|
||||
$charInfo = $lookup->GetCharacterInfo($ledger->character_id);
|
||||
//Get the corporation info from the lookup helper
|
||||
$corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
namespace App\Jobs\Commands;
|
||||
|
||||
//Internal Library
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Log;
|
||||
|
||||
//App Library
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use App\Library\Esi\Esi;
|
||||
use App\Library\Lookups\LookupHelper;
|
||||
|
||||
//App Models
|
||||
use App\Models\Moon\CorpMoonObserver;
|
||||
|
||||
class FetchMoonObserversJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Timeout in seconds
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Retries
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $retries = 3;
|
||||
|
||||
/**
|
||||
* Private variables
|
||||
*/
|
||||
private $charId;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($charId)
|
||||
{
|
||||
//
|
||||
$this->charId = $charId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,6 +58,49 @@ class FetchMoonObserversJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
//Declare some variables
|
||||
$lookup = new LookupHelper;
|
||||
$structure = new StructureHelper;
|
||||
$esi = new Esi;
|
||||
|
||||
//Get the configuration from the main site
|
||||
$config = config('esi');
|
||||
|
||||
//Check for the esi scope
|
||||
if(!$esiHelper->HaveEsiScope($this->charId, 'esi-industry.read_corporation_mining.v1') || !$esiHelper->HaveEsiScope($this->charId, 'esi-universe.read_structures.v1')) {
|
||||
Log::warning('Esi scopes were not found for Fetch Moon Observers job.');
|
||||
return;
|
||||
}
|
||||
|
||||
//Get the refresh token for the character
|
||||
$refreshToken = $esiHelper->GetRefreshToken($this->charId);
|
||||
|
||||
//Get the mining observers for the corporation's from esi
|
||||
try {
|
||||
$responses = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [
|
||||
'corporation_id' => $character->corporation_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
Log::critical('FetchMoonObservers failed to get the moon observers for the corporation');
|
||||
}
|
||||
|
||||
//Run through the mining observers, and add them to the database as needed
|
||||
foreach($response as $observer) {
|
||||
CorpMoonObserver::where(['observer_id' => $observer->observer_id])->count();
|
||||
//If the observer is not found, then add it to the database
|
||||
if($count == 0) {
|
||||
$obs = new CorpMoonObserver;
|
||||
$obs->observer_id = $observer->observer_id;
|
||||
$obs->observer_type = $observer->observer_type;
|
||||
$obs->last_updated = $esi->DecodeDate($observer->last_updated);
|
||||
$obs->save();
|
||||
} else {
|
||||
CorpMoonObserver::where([
|
||||
'observer_id' => $observer->observer_id,
|
||||
])->update([
|
||||
'last_updated' => $esi->DecodeDate($observer->last_updated),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,20 @@ class FetchRentalMoonLedgerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Timeout in seconds
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Retries
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $retries = 3;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@@ -41,12 +55,8 @@ class FetchRentalMoonLedgerJob implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
//Declare variables
|
||||
$structures = array();
|
||||
$miningLedgers = array();
|
||||
$tempMiningLedger = array();
|
||||
$esiHelper = new Esi;
|
||||
$lookup = new LookupHelper;
|
||||
$structure = new StructureHelper;
|
||||
$response = null;
|
||||
$structureInfo = null;
|
||||
|
||||
@@ -103,7 +113,7 @@ class FetchRentalMoonLedgerJob implements ShouldQueue
|
||||
$newLedger->observer_id = $observer->observer_id;
|
||||
$newLedger->observer_name = $observerName;
|
||||
$newLedger->type_id = $ledger->type_id;
|
||||
$newLedger->ore = $ore ;
|
||||
$newLedger->ore = $ore;
|
||||
$newLedger->quantity = $ledger->quantity;
|
||||
$newLedger->recorded_corporation_id = $ledger->recorded_corporation_id;
|
||||
$newLedger->recorded_corporation_name = $recordedCorpName;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
namespace App\Jobs\Commands;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
@@ -13,17 +13,29 @@ 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\RentalMoon;
|
||||
use App\Models\Moon\RentalMoonObserver;
|
||||
|
||||
class FetchRentalMoonObserversJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Timeout in seconds
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Retries
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $retries = 3;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@@ -43,7 +55,6 @@ class FetchRentalMoonObserversJob implements ShouldQueue
|
||||
{
|
||||
//Declare some variables
|
||||
$lookup = new LookupHelper;
|
||||
$structure = new StructureHelper;
|
||||
$esi = new Esi;
|
||||
|
||||
//Get the configuration for the main site
|
||||
|
||||
@@ -29,4 +29,13 @@ class RentalMoonLedger extends Model
|
||||
'recorded_corporation_name',
|
||||
'last_updated',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the observer this belongs to
|
||||
*/
|
||||
public function observer() {
|
||||
return $this->belongsTo('App\Models\Moon\RentalMoonObserver', 'observer_id', 'observer_id');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,5 +22,5 @@ class RentalMoonObserver extends Model
|
||||
'observer_name',
|
||||
'observer_type',
|
||||
'last_updated',
|
||||
];
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user