re-arranged function

This commit is contained in:
2019-05-30 02:46:53 -05:00
parent 2ae0b3f97d
commit 82c9f6d762
2 changed files with 50 additions and 27 deletions

View File

@@ -97,8 +97,7 @@ class GetStructuresCommand extends Command
$totalPages = 1; $totalPages = 1;
try { try {
$structures = $esi->page($currentPage) $structures = $esi->invoke('get', '/corporations/{corporation_id}/structures/', [
->invoke('get', '/corporations/{corporation_id}/structures/', [
'corporation_id' => $corpId, 'corporation_id' => $corpId,
]); ]);
} catch (RequestFailedException $e) { } catch (RequestFailedException $e) {
@@ -111,7 +110,7 @@ class GetStructuresCommand extends Command
$job->charId = $charId; $job->charId = $charId;
$job->corpId = $corpId; $job->corpId = $corpId;
$job->page = $i; $job->page = $i;
ProcessStructureJob::dispatch($job)->onQueue('default'); ProcessStructureJob::dispatch($job)->onQueue('structures');
} }
//Mark the job as finished //Mark the job as finished

View File

@@ -31,35 +31,24 @@ use App\Models\Esi\EsiScope;
class StructureHelper { class StructureHelper {
public function Start($charId, $corpId, $page) { public function Start($charId, $corpId, $page) {
//Setup the esi authentication container
$config = config('esi');
//Get the refresh token from the database
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
$esi = new Eseye($authentication); $structures = $this->GetListOfStructures($page, $corpId);
$structures = $this->GetListOfStructures($page, $corpId, $esi);
foreach($structures as $structure) { foreach($structures as $structure) {
$info = $this->GetStructureInfo($structure->structure_id, $esi); $info = $this->GetStructureInfo($structure->structure_id);
//Record the structure information into the database
//Find if the structure exists
$found = Structure::where(['structure_id' => $structure->structure_id])->get();
if(!$found) {
if(isset($info->solar_system_id)) { if(isset($info->solar_system_id)) {
$solarName = $this->GetSolarSystemName($info->solar_system_id, $esi); $solarName = $this->GetSolarSystemName($info->solar_system_id);
} else { } else {
Log::critical("Couldn't get solar system name for structure " . $structure->structure_id); Log::critical("Couldn't get solar system name for structure " . $structure->structure_id);
Log::critical("Check access lists."); Log::critical("Check access lists.");
$solarName = null; $solarName = null;
} }
//Record the structure information into the database
//Find if the structure exists
$found = Structure::where(['structure_id' => $structure->structure_id])->get();
if(!$found) {
$sHelper->StoreNewStructure($structure, $info, $solarName); $sHelper->StoreNewStructure($structure, $info, $solarName);
} else { } else {
$sHelper->UpdateExistingStructure($structure, $info, $solarName); $sHelper->UpdateExistingStructure($structure, $info, $solarName);
@@ -150,7 +139,18 @@ class StructureHelper {
$struct->save(); $struct->save();
} }
private function GetSolarSystemName($systemId, $esi) { private function GetSolarSystemName($systemId) {
//Setup the esi authentication container
$config = config('esi');
//Get the refresh token from the database
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
$esi = new Eseye($authentication);
//Attempt to get the solar system name from ESI //Attempt to get the solar system name from ESI
try { try {
@@ -168,7 +168,19 @@ class StructureHelper {
} }
} }
private function GetStructureInfo($structureId, $esi) { private function GetStructureInfo($structureId) {
//Setup the esi authentication container
$config = config('esi');
//Get the refresh token from the database
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
$esi = new Eseye($authentication);
try { try {
$info = $esi->invoke('get', '/universe/structures/{structure_id}/', [ $info = $esi->invoke('get', '/universe/structures/{structure_id}/', [
'structure_id' => $structureId, 'structure_id' => $structureId,
@@ -185,7 +197,19 @@ class StructureHelper {
return $info; return $info;
} }
private function GetListOfStructures($page, $corpId, $esi) { private function GetListOfStructures($page, $corpId) {
//Setup the esi authentication container
$config = config('esi');
//Get the refresh token from the database
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
$esi = new Eseye($authentication);
try { try {
$structures = $esi->page($page) $structures = $esi->page($page)
->invoke('get', '/corporations/{corporation_id}/structures/', [ ->invoke('get', '/corporations/{corporation_id}/structures/', [