cleaned up unnecessary commands as they got switched to working as jobs.
updated the structure library to be able to be passed the esi connection added new jobs for the fetch stuff that was being previously done as commands.
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Moons;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FetchMoonObserversCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'services:FetchMoonObservers';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fetch Moon Observers';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//Create the command helper container
|
||||
$task = new CommandHelper('FetchMoonObservers');
|
||||
//Add the entry into the jobs table saying the job has started
|
||||
$task->SetStartStatus();
|
||||
|
||||
//Declare some variables
|
||||
$lookup = new LookupHelper;
|
||||
$esi = new Esi;
|
||||
|
||||
//Get the configuration from the main site
|
||||
$config = config('esi');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -30,9 +30,7 @@ class Kernel extends ConsoleKernel
|
||||
Commands\Finances\SovBillsCommand::class,
|
||||
Commands\Data\CleanStaleDataCommand::class,
|
||||
//Commands\Moons\FetchMoonLedgerCommand::class,
|
||||
//Commands\Moons\FetchMoonObserversCommand::class,
|
||||
//Commands\Moons\FetchRentalMoonLedgerCommand::class,
|
||||
//Commands\Moons\FetchRentalMoonObserversCommand::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
37
app/Jobs/Commands/FetchMoonLedgerJob.php
Normal file
37
app/Jobs/Commands/FetchMoonLedgerJob.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
//Internal Libraries
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Log;
|
||||
|
||||
|
||||
class FetchMoonLedgerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
34
app/Jobs/Commands/FetchMoonObserversJob.php
Normal file
34
app/Jobs/Commands/FetchMoonObserversJob.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class FetchMoonObserversJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
116
app/Jobs/Commands/FetchRentalMoonLedgerJob.php
Normal file
116
app/Jobs/Commands/FetchRentalMoonLedgerJob.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Commands;
|
||||
|
||||
//Internal Libraries
|
||||
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\RentalMoonLedger;
|
||||
use App\Models\RentalMoonObserver;
|
||||
|
||||
class FetchRentalMoonLedgerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//Declare variables
|
||||
$structures = array();
|
||||
$miningLedgers = array();
|
||||
$tempMiningLedger = array();
|
||||
$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 the esi scope
|
||||
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1') || !$esiHelper->HaveEsiScope($config['primary'], 'esi-universe.read_structures.v1')) {
|
||||
Log::critical('The primary character does not have the necessary scopes for FetchRentalMoonLedgerCommand.');
|
||||
return;
|
||||
}
|
||||
|
||||
//Get the refresh token if scope checks have passed
|
||||
$refreshToken = $esiHelper->GetRefreshtoken($config['primary']);
|
||||
|
||||
//Get the character data from the lookup table if possible or esi
|
||||
$character = $lookup->GetCharacterInfo($config['primary']);
|
||||
|
||||
//Get all of the rental moon observers from the database
|
||||
$observers = RentalMoonObserver::all();
|
||||
|
||||
//Dump the mining ledger table for rental moons
|
||||
RentalMoonLedger::truncate();
|
||||
|
||||
//Foreach observer get the ledger
|
||||
foreach($observers as $observer) {
|
||||
//Get the observer name.
|
||||
|
||||
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) {
|
||||
//If an exception has occurred, then log it
|
||||
Log::critical('FetchRentalMoonLedger command failed to get the mining ledger for observer id: ' . $observer->observer_id);
|
||||
}
|
||||
|
||||
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 using the characterId
|
||||
$charInfo = $lookup->GetCharacterInfo($ledger->character_id);
|
||||
//Get the corporation information
|
||||
$corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id);
|
||||
|
||||
$newLedger = new RentalMoonLedger;
|
||||
$newLedger->corporation_id = $corpId;
|
||||
$newLedger->corporation_name = $corpName;
|
||||
$newLedger->character_id = $ledger->character_id;
|
||||
$newLedger->character_name = $charInfo->name;
|
||||
$newLedger->observer_id = $observer->observer_id;
|
||||
$newLedger->observer_name = $observerName;
|
||||
$newLedger->type_id = $ledger->type_id;
|
||||
$newLedger->ore = $ore ;
|
||||
$newLedger->quantity = $ledger->quantity;
|
||||
$newLedger->recorded_corporation_id = $ledger->recorded_corporation_id;
|
||||
$newLedger->recorded_corporation_name = $recordedCorpName;
|
||||
$newLedger->last_updated = $ledger->last_updated;
|
||||
$newLedger->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Moons;
|
||||
namespace App\Jobs;
|
||||
|
||||
//Internal Library
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Log;
|
||||
use Carbon\Carbon;
|
||||
|
||||
//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\Moon\RentalMoon;
|
||||
use App\Models\Moon\RentalMoonObserver;
|
||||
|
||||
class FetchRentalMoonObserversCommand extends Command
|
||||
class FetchRentalMoonObserversJob implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'services:FetchRentalMoonObservers';
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fetch the rental moon observers';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* Execute the job.
|
||||
*
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//Create the command helper container
|
||||
$task = new CommandHelper('RentalMoonObservers');
|
||||
//Add the entry into the jobs table saying the job has started
|
||||
$task->SetStartStatus();
|
||||
|
||||
//Declare some variables
|
||||
$lookup = new LookupHelper;
|
||||
$structure = new StructureHelper;
|
||||
$esi = new Esi;
|
||||
|
||||
//Get the configuration for the main site
|
||||
@@ -99,8 +88,5 @@ class FetchRentalMoonObserversCommand extends Command
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
//Mark the job as finished
|
||||
$task->SetStopStatus();
|
||||
}
|
||||
}
|
||||
@@ -31,24 +31,30 @@ class StructureHelper {
|
||||
private $charId;
|
||||
private $corpId;
|
||||
private $page;
|
||||
private $esi;
|
||||
|
||||
public function __construct($char, $corp) {
|
||||
public function __construct($char, $corp, $esi = null) {
|
||||
$this->charId = $char;
|
||||
$this->corpId = $corp;
|
||||
$this->esi = $esi;
|
||||
}
|
||||
|
||||
public function GetStructuresByPage($page) {
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Create the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
if($this->esi == null) {
|
||||
//Get the refresh token from the database
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Create the esi authentication container
|
||||
$this->esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Try to get the ESI data
|
||||
try {
|
||||
$structures = $esi->page($page)
|
||||
$structures = $this->esi->page($page)
|
||||
->invoke('get', '/corporations/{corporation_id}/structures/', [
|
||||
'corporation_id' => $this->corpId,
|
||||
]);
|
||||
@@ -67,7 +73,7 @@ class StructureHelper {
|
||||
//Get the refresh token from the database
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
$this->esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
//Get the structure information
|
||||
$info = $this->GetStructureInfo($structure->structure_id);
|
||||
@@ -86,14 +92,17 @@ class StructureHelper {
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Get the refresh token
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
if($this->esi == null) {
|
||||
//Get the refresh token
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Setup the esi authentication container
|
||||
$this->esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
}
|
||||
|
||||
|
||||
//Attempt to get the solar system name from ESI
|
||||
try {
|
||||
$solar = $esi->invoke('get', '/universe/systems/{system_id}/', [
|
||||
$solar = $this->esi->invoke('get', '/universe/systems/{system_id}/', [
|
||||
'system_id' => $systemId,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
@@ -111,10 +120,13 @@ class StructureHelper {
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Get the refresh token
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
if($this->esi == null) {
|
||||
//Get the refresh token
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Setup the esi authentication container
|
||||
$this->esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$info = $esi->invoke('get', '/universe/structures/{structure_id}/', [
|
||||
|
||||
Reference in New Issue
Block a user