converting all lookup functions to the new lookup helper
This commit is contained in:
@@ -9,12 +9,8 @@ use Carbon\Carbon;
|
||||
|
||||
//App Library
|
||||
use App\Jobs\Library\JobHelper;
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use App\Library\Esi\Esi;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
|
||||
use App\Models\Jobs\JobProcessAsset;
|
||||
use App\Models\Jobs\JobStatus;
|
||||
@@ -41,12 +37,6 @@ class AssetHelper {
|
||||
//Declare the variable for the esi helper
|
||||
$esiHelper = new Esi;
|
||||
|
||||
// Disable all caching by setting the NullCache as the
|
||||
// preferred cache handler. By default, Eseye will use the
|
||||
// FileCache.
|
||||
$configuration = Configuration::getInstance();
|
||||
$configuration->cache = NullCache::class;
|
||||
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
|
||||
@@ -59,13 +49,8 @@ class AssetHelper {
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
//Setup the ESI variable
|
||||
$esi = new Eseye($authentication);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
try {
|
||||
$assets = $esi->page($this->page)
|
||||
|
||||
@@ -8,11 +8,6 @@ use DB;
|
||||
|
||||
//App Library
|
||||
use App\Jobs\Library\JobHelper;
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use App\Library\Esi\Esi;
|
||||
|
||||
//Models
|
||||
@@ -38,14 +33,8 @@ class EveContractsHelper {
|
||||
* Get a page of Contracts to store in the database
|
||||
*/
|
||||
public function GetContractsByPage() {
|
||||
// Disable all caching by setting the NullCache as the
|
||||
// preferred cache handler. By default, Eseye will use the
|
||||
// FileCache.
|
||||
$configuration = Configuration::getInstance();
|
||||
$configuration->cache = NullCache::class;
|
||||
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Check for the scope for the esi token needed
|
||||
$hasScope = $esiHelper->HaveEsiScope($this->charId, 'esi-contracts.read_corporation_contracts.v1');
|
||||
@@ -56,13 +45,8 @@ class EveContractsHelper {
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
//Setup the ESI variable
|
||||
$esi = new Eseye($authentication);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
try {
|
||||
$contracts = $esi->page($this->page)
|
||||
@@ -84,9 +68,6 @@ class EveContractsHelper {
|
||||
//Declare esi helper for decoding the date
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
|
||||
//Check if the scope is present for ESI
|
||||
$hasScope = $esiHelper->HaveEsiScope($this->charId, 'esi-contracts.read_corporation_contracts.v1');
|
||||
if($hasScope == false) {
|
||||
@@ -96,13 +77,8 @@ class EveContractsHelper {
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
//Setup the ESI variable
|
||||
$esi = new Eseye($authentication);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
//See if we find the contract in the database
|
||||
$found = LogisticsContract::where([
|
||||
|
||||
@@ -106,23 +106,6 @@ class Esi {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
/*
|
||||
try {
|
||||
$character = $esi->setQueryString([
|
||||
'categories' => 'character',
|
||||
'language' => 'en-us',
|
||||
'search' => $name,
|
||||
'strict' => 'true',
|
||||
])->invoke('get', '/search/');
|
||||
} catch(RequestFailedException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$character = json_decode($character, true);
|
||||
|
||||
return $character['character'];
|
||||
*/
|
||||
}
|
||||
|
||||
public function FindCorporationId($charId) {
|
||||
|
||||
+10
-14
@@ -2,33 +2,29 @@
|
||||
|
||||
namespace App\Library\Esi;
|
||||
|
||||
use DB;
|
||||
|
||||
//Models
|
||||
use App\Models\Esi\EsiScope;
|
||||
use App\Models\Esi\EsiToken;
|
||||
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
//Library
|
||||
use App\Library\Esi\Esi;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
|
||||
class Mail {
|
||||
|
||||
public function SendMail($recipient, $rType, $subject, $body) {
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Get the esi config
|
||||
$config = config('esi');
|
||||
|
||||
//Retrieve the token for main character to send mails from
|
||||
$token = EsiToken::where(['character_id' => $config['primary']])->first();
|
||||
$token = $esiHelper->GetRefreshToken($config['primary']);
|
||||
//Create the ESI authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token->refresh_token,
|
||||
]);
|
||||
$esi = new Eseye($authentication);
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
//Try to send the mail
|
||||
try {
|
||||
$esi->setBody([
|
||||
'approved_cost' => 0,
|
||||
|
||||
@@ -31,7 +31,7 @@ use App\Library\Finances\StructureIndustryTax;
|
||||
use App\Library\Finances\OfficeFee;
|
||||
use App\Library\Finances\PlanetProductionTax;
|
||||
use App\Library\Finances\PISale;
|
||||
use App\Library\Lookups\LookupHelper;
|
||||
use App\Library\Lookups\NewLookupHelper;
|
||||
|
||||
//Seat Stuff
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
@@ -50,7 +50,7 @@ class FinanceHelper {
|
||||
$industry = new StructureIndustryTax();
|
||||
$office = new OfficeFee();
|
||||
$esiHelper = new Esi();
|
||||
$lookups = new LookupHelper;
|
||||
$lookup = new NewLookupHelper;
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$hasScope = $esiHelper->HaveEsiScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
@@ -64,18 +64,11 @@ class FinanceHelper {
|
||||
}
|
||||
|
||||
//Reference to see if the character is in our look up table for corporations and characters
|
||||
$corpId = $lookups->LookupCharacter($charId);
|
||||
$corpId = $lookup->LookupCharacter($charId, null);
|
||||
|
||||
//Create an ESI authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
|
||||
//Create the esi class varialble
|
||||
$esi = new Eseye($authentication);
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
//Set the version
|
||||
$esi->setVersion('v4');
|
||||
|
||||
//Set our current page to 1 which is the one we are starting on.
|
||||
@@ -131,8 +124,8 @@ class FinanceHelper {
|
||||
|
||||
public function GetJournalPageCount($division, $charId) {
|
||||
//Declare class variables
|
||||
$lookups = new LookupHelper();
|
||||
$esiHelper = new Esi();
|
||||
$lookup = new NewLookupHelper;
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$hasScope = $esiHelper->HaveEsiScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
@@ -146,18 +139,12 @@ class FinanceHelper {
|
||||
}
|
||||
|
||||
//Refrence to see if the character is in our look up table for corporation and characters
|
||||
$corpId = $lookups->LookupCharacter($charId);
|
||||
$corpId = $lookup->LookupCharacter($charId, null);
|
||||
|
||||
//Create the ESI authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
//Create the esi class variable
|
||||
$esi = new Eseye($authentication);
|
||||
//Set the esi version to v4
|
||||
$esi->setVersion('v4');
|
||||
|
||||
//Call the first page so we can get the header data for the number of pages
|
||||
@@ -179,22 +166,13 @@ class FinanceHelper {
|
||||
public function GetCorpWalletJournalPage($division, $charId, $corpId, $page = 1) {
|
||||
//Declare new class variables
|
||||
$corpMarket = new MarketTax();
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$tokenData = $this->TokenIfno($charId);
|
||||
$token = $tokenData['token'];
|
||||
$scope = $tokenData['scope'];
|
||||
$token = $esiHelper->GetRefreshToken($charId);
|
||||
|
||||
//Create an ESI authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
|
||||
//Create the esi class varialble
|
||||
$esi = new Eseye($authentication);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
$esi->setVersion('v4');
|
||||
|
||||
//Call the page of the wallet journal
|
||||
@@ -232,7 +210,7 @@ class FinanceHelper {
|
||||
$office = new OfficeFee;
|
||||
$pi = new PlanetProductionTax;
|
||||
$esiHelper = new Esi;
|
||||
$lookups = new LookupHelper;
|
||||
$lookup = new NewLookupHelper;
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$hasScope = $esiHelper->HaveEsiScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
@@ -246,18 +224,11 @@ class FinanceHelper {
|
||||
}
|
||||
|
||||
//Reference to see if the character is in our look up table for corporations and characters
|
||||
$corpId = $lookups->LookupCorporationId($charId);
|
||||
$char = $lookup->LookupCharacter($charId, null);
|
||||
$corpId = $char->corporation_id;
|
||||
|
||||
//Create an ESI authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
|
||||
//Create the esi class varialble
|
||||
$esi = new Eseye($authentication);
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
$esi->setVersion('v4');
|
||||
|
||||
//Call the first page of the wallet journal, as we are always going to get at least one page.
|
||||
|
||||
@@ -1,328 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Lookups;
|
||||
|
||||
use DB;
|
||||
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
|
||||
use App\Models\Lookups\CharacterToCorporation;
|
||||
use App\Models\Lookups\CorporationToAlliance;
|
||||
|
||||
class LookupHelper {
|
||||
|
||||
public function CharacterName($charId) {
|
||||
$esi = new Eseye();
|
||||
|
||||
try {
|
||||
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||
'character_id' => $charId,
|
||||
]);
|
||||
} catch(RequestFailedException $e){
|
||||
return null;
|
||||
}
|
||||
|
||||
return $character->name;
|
||||
}
|
||||
|
||||
//Create a character id from a character name
|
||||
public function CharacterNameToId($character) {
|
||||
//Setup class variables
|
||||
$esi = new Eseye();
|
||||
|
||||
//Attempt to find the character name in the LookupCharacter table to see if we can match it to an id
|
||||
$count = CharacterToCorporation::where(['character_name' => $character])->count();
|
||||
if($count === 0) {
|
||||
//Format the name
|
||||
$name = str_replace(' ', '%20', $character);
|
||||
//dd($name);
|
||||
try {
|
||||
//Get the character id from the ESI API.
|
||||
$response = $esi->setBody(array(
|
||||
$character,
|
||||
))->invoke('post', '/universe/ids/');
|
||||
} catch(RequestFailedException $e) {
|
||||
|
||||
}
|
||||
|
||||
//If the data we are looking for is set, then process the data
|
||||
if(isset($response->characters[0]->id)) {
|
||||
$this->LookupCharacter($response->characters[0]->id);
|
||||
|
||||
return $response->characters[0]->id;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
$char = CharacterToCorporation::where(['character_name' => $character])->get(['character_id'])->first();
|
||||
|
||||
return $char->character_id;
|
||||
}
|
||||
}
|
||||
|
||||
//Add characters to the lookup table for quicker lookups without having
|
||||
//to hit the ESI all the time
|
||||
public function LookupCharacter($charId) {
|
||||
//Check for the character in the user_to_corporation table
|
||||
$count = CharacterToCorporation::where('character_id', $charId)->count();
|
||||
|
||||
//If we don't find the character in the table, then we retrieve from ESI
|
||||
//and add the character to the table
|
||||
if($count == 0) {
|
||||
//Get the configuration for ESI from the environmental variables
|
||||
$config = config('esi');
|
||||
|
||||
//Setup a new ESI container
|
||||
$esi = new Eseye();
|
||||
|
||||
//Try to get the character information, then the corporation information
|
||||
try {
|
||||
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||
'character_id' => $charId,
|
||||
]);
|
||||
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||
'corporation_id' => $character->corporation_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e){
|
||||
return null;
|
||||
}
|
||||
|
||||
//Save all of the data to the database
|
||||
$char = new CharacterToCorporation;
|
||||
$char->character_id = $charId;
|
||||
$char->character_name = $character->name;
|
||||
$char->corporation_id = $character->corporation_id;
|
||||
$char->corporation_name = $corporation->name;
|
||||
$char->save();
|
||||
//Return the corporation_id which is what the calling function is looking for
|
||||
return $character->corporation_id;
|
||||
} else {
|
||||
$found = CharacterToCorporation::where('character_id', $charId)->get(['corporation_id']);
|
||||
|
||||
//Return the corporation_id if it was found in the database as it is what the calling function is looking for
|
||||
return $found[0]->corporation_id;
|
||||
}
|
||||
}
|
||||
|
||||
public function LookupCorporationId($charId) {
|
||||
//Check for the character in the user_to_corporation table
|
||||
$count = CharacterToCorporation::where('character_id', $charId)->count();
|
||||
|
||||
//If we don't find the character in the table, then we retrieve from ESI
|
||||
//and add the character to the table
|
||||
if($count == 0) {
|
||||
//Get the configuration for ESI from the environmental variables
|
||||
$config = config('esi');
|
||||
|
||||
//Setup a new ESI container
|
||||
$esi = new Eseye();
|
||||
|
||||
//Try to get the character information, then the corporation information
|
||||
try {
|
||||
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||
'character_id' => $charId,
|
||||
]);
|
||||
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||
'corporation_id' => $character->corporation_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e){
|
||||
return null;
|
||||
}
|
||||
|
||||
//Save all of the data to the database
|
||||
$char = new CharacterToCorporation;
|
||||
$char->character_id = $charId;
|
||||
$char->character_name = $character->name;
|
||||
$char->corporation_id = $character->corporation_id;
|
||||
$char->corporation_name = $corporation->name;
|
||||
$char->save();
|
||||
//Return the corporation_id which is what the calling function is looking for
|
||||
return $character->corporation_id;
|
||||
} else {
|
||||
$found = CharacterToCorporation::where('character_id', $charId)->get(['corporation_id']);
|
||||
|
||||
//Return the corporation_id if it was found in the database as it is what the calling function is looking for
|
||||
return $found[0]->corporation_id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to retrieve a corporation name from the lookup tables
|
||||
* or add the details of the corporation if it's not found
|
||||
*
|
||||
*/
|
||||
public function LookupCorporationName($corpId) {
|
||||
//check for the character in the user_to_corporation table
|
||||
$count = CorporationToAlliance::where('corporation_id', $corpId)->count();
|
||||
|
||||
//If we don't find the corporation in the table, then we need to retrieve it from ESI
|
||||
//and add the corporation to the table
|
||||
if($count == 0) {
|
||||
//Get the configuration for ESI from the environmental variables
|
||||
$config = config('esi');
|
||||
|
||||
//Setup a new ESI container
|
||||
$esi = new Eseye();
|
||||
|
||||
try {
|
||||
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||
'corporation_id' => $corpId,
|
||||
]);
|
||||
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e){
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
|
||||
//Return the corporation name
|
||||
return $corporation->name;
|
||||
} else {
|
||||
$found = CorporationToAlliance::where('corporation_id', $corpId)->get(['corporation_name']);
|
||||
|
||||
return $found[0]->corporation_name;
|
||||
}
|
||||
}
|
||||
|
||||
//Add corporations to the lookup table for quicker lookups without having to
|
||||
//hit the ESI API all the time
|
||||
public function LookupCorporation($corpId) {
|
||||
//Check for the character in the user_to_corporation table
|
||||
$count = CorporationToAlliance::where('corporation_id', $corpId)->count();
|
||||
|
||||
//If we don't find the character in the table, then we retrieve from ESI
|
||||
//and add the character to the table
|
||||
if($count == 0) {
|
||||
//Get the configuration for ESI from the environmental variables
|
||||
$config = config('esi');
|
||||
|
||||
//Setup a new ESI container
|
||||
$esi = new Eseye();
|
||||
|
||||
//Try to get the character information, then the corporation information
|
||||
try {
|
||||
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||
'corporation_id' => $corpId,
|
||||
]);
|
||||
if(isset($corporation->alliance_id)) {
|
||||
$alliance = $esi->invoke('get', '/alliances/{alliance_id}/', [
|
||||
'alliance_id' => $corporation->alliance_id,
|
||||
]);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e){
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Save all of the data to the database
|
||||
$corp = new CorporationToAlliance;
|
||||
$corp->corporation_id = $corpId;
|
||||
$corp->corporation_name = $corporation->name;
|
||||
$corp->alliance_id = $corporation->alliance_id;
|
||||
$corp->alliance_name = $alliance->name;
|
||||
$corp->save();
|
||||
|
||||
//Return the corporation_id which is what the calling function is looking for
|
||||
return $corporation->alliance_id;
|
||||
} else {
|
||||
$found = CorporationToAlliance::where('corporation_id', $corpId)->get(['alliance_id']);
|
||||
|
||||
//Return the corporation_id if it was found in the database as it is what the calling function is looking for
|
||||
return $found[0]->alliance_id;
|
||||
}
|
||||
}
|
||||
|
||||
public function LookupAllianceTicker($allianceId) {
|
||||
//Get the configuration for ESI from the environmental variable
|
||||
$config = config('esi');
|
||||
|
||||
//Setup a new ESI container
|
||||
$esi = new Eseye();
|
||||
|
||||
try {
|
||||
$alliance = $esi->invoke('get', '/alliances/{alliance_id}/', [
|
||||
'alliance_id' => $allianceId,
|
||||
]);
|
||||
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e){
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
|
||||
return $alliance->ticker;
|
||||
}
|
||||
|
||||
//Update the character lookup table as often as necessary
|
||||
public function UpdateLookupCharacter() {
|
||||
//Create a new ESI container
|
||||
$esi = new Eseye();
|
||||
|
||||
//Get all of the data from the database and start performing updates
|
||||
$dbChars = CharacterToCorporation::all();
|
||||
foreach($dbChars as $char) {
|
||||
//Attempt to get the data from the ESI API
|
||||
try{
|
||||
$charcter = $esi->invoke('get', '/characters/{character_id}/', [
|
||||
'character_id' => $char->character_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
|
||||
//Check the response versus the database
|
||||
if($char->corporation_id != $character->corporation_id) {
|
||||
try {
|
||||
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||
'corporation_id' => $character->corporation_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
CharacterToCorporation::where(['character_id' => $char->character_id])
|
||||
->update([
|
||||
'corporation_id' => $character->corporation_id,
|
||||
'corporation_name' => $corporation->name,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Update the corporation lookup table as often as necessary
|
||||
public function UpdateLookupCorporation() {
|
||||
//Create a new ESI container
|
||||
$esi = new Eseye();
|
||||
|
||||
//Get all of the data from the database and start performing updates
|
||||
$dbCorps = CorporationToAlliance::all();
|
||||
foreach($dbCorps as $corp) {
|
||||
//Attempt to get the data from the ESI API
|
||||
try{
|
||||
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||
'corporation_id' => $corp->corporation_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
|
||||
//Check the response versus the database
|
||||
if($corp->corporation_id != $corporation->corporation_id) {
|
||||
try {
|
||||
$alliance = $esi->invoke('get', '/alliancess/{alliance_id}/', [
|
||||
'alliance_id' => $corporation->alliance_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
CorporationToAlliance::where(['corporation_id' => $char->character_id])
|
||||
->update([
|
||||
'alliance_id' => $corporation->alliance_id,
|
||||
'alliance_name' => $alliance->name,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -15,10 +15,6 @@ use DB;
|
||||
|
||||
//App Library
|
||||
use App\Jobs\Library\JobHelper;
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use App\Library\Esi\Esi;
|
||||
|
||||
@@ -43,23 +39,13 @@ class StructureHelper {
|
||||
}
|
||||
|
||||
public function GetStructuresByPage($page) {
|
||||
// Disable all caching by setting the NullCache as the
|
||||
// preferred cache handler. By default, Eseye will use the
|
||||
// FileCache.
|
||||
$configuration = Configuration::getInstance();
|
||||
$configuration->cache = NullCache::class;
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id' => $this->charId])->get(['refresh_token']);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
]);
|
||||
//Setup the ESI variable
|
||||
$esi = new Eseye($authentication);
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Create the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
//Try to get the ESI data
|
||||
try {
|
||||
@@ -76,18 +62,15 @@ class StructureHelper {
|
||||
}
|
||||
|
||||
public function ProcessStructure($structure) {
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id' => $this->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);
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
//Get the structure information
|
||||
$info = $this->GetStructureInfo($structure->structure_id);
|
||||
|
||||
//Record the structure information into the database
|
||||
@@ -101,17 +84,13 @@ class StructureHelper {
|
||||
}
|
||||
|
||||
private function GetSolarSystemName($systemId) {
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id' => $this->charId])->get(['refresh_token']);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
]);
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
|
||||
$esi = new Eseye($authentication);
|
||||
//Get the refresh token
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
//Attempt to get the solar system name from ESI
|
||||
try {
|
||||
@@ -130,17 +109,13 @@ class StructureHelper {
|
||||
}
|
||||
|
||||
private function GetStructureInfo($structureId) {
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id' => $this->charId])->get(['refresh_token']);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
]);
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
|
||||
$esi = new Eseye($authentication);
|
||||
//Get the refresh token
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
//Setup the esi authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
try {
|
||||
$info = $esi->invoke('get', '/universe/structures/{structure_id}/', [
|
||||
@@ -383,7 +358,7 @@ class StructureHelper {
|
||||
}
|
||||
|
||||
private function DecodeDate($date) {
|
||||
$esiHelper = new Esi();
|
||||
$esiHelper = new Esi;
|
||||
|
||||
$dateTime = $esiHelper->DecodeDate($date);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user