From 9e47568e678b935fe4e312ddd18e45f800135b79 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Wed, 11 Dec 2019 21:23:13 -0600 Subject: [PATCH] converting all lookup functions to the new lookup helper --- app/Console/Commands/Assets/GetAssets.php | 18 +- .../Commands/Finances/CorpFinances.php | 3 - .../Commands/Structures/GetStructures.php | 15 +- .../Contracts/ContractController.php | 11 +- .../Moons/MoonsAdminController.php | 9 +- app/Http/Controllers/Wiki/WikiController.php | 17 +- app/Jobs/ProcessSendEveMailJob.php | 23 +- app/Library/Assets/AssetHelper.php | 21 +- app/Library/Contracts/EveContractsHelper.php | 36 +- app/Library/Esi/Esi.php | 17 - app/Library/Esi/Mail.php | 24 +- app/Library/Finances/Helper/FinanceHelper.php | 65 +--- app/Library/Lookups/LookupHelper.php | 328 ------------------ app/Library/Structures/StructureHelper.php | 75 ++-- 14 files changed, 98 insertions(+), 564 deletions(-) delete mode 100644 app/Library/Lookups/LookupHelper.php diff --git a/app/Console/Commands/Assets/GetAssets.php b/app/Console/Commands/Assets/GetAssets.php index b32fea583..811260ffd 100644 --- a/app/Console/Commands/Assets/GetAssets.php +++ b/app/Console/Commands/Assets/GetAssets.php @@ -11,10 +11,6 @@ use App\Jobs\ProcessAssetsJob; //Library use App\Library\Esi\Esi; -use Seat\Eseye\Cache\NullCache; -use Seat\Eseye\Configuration; -use Seat\Eseye\Containers\EsiAuthentication; -use Seat\Eseye\Eseye; use Commands\Library\CommandHelper; use App\Library\Assets\AssetHelper; @@ -79,23 +75,11 @@ class GetAssetsCommand extends Command Log::critical("Scope check for esi-assets.read_corporation_assets.v1 failed."); return null; } - - // 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; //Get the refresh token from the database $token = $esiHelper->GetRefreshToken($charId); //Create the authentication container - $authentication = new EsiAuthentication([ - 'client_id' => $config['client_id'], - 'secret' => $config['secret'], - 'refresh_token' => $token, - ]); - - $esi = new Eseye($authentication); + $esi = $esiHelper->SetupEsiAuthentication($token); try { $assets = $esi->page(1) diff --git a/app/Console/Commands/Finances/CorpFinances.php b/app/Console/Commands/Finances/CorpFinances.php index 7e5ed195d..4b6271864 100644 --- a/app/Console/Commands/Finances/CorpFinances.php +++ b/app/Console/Commands/Finances/CorpFinances.php @@ -56,9 +56,6 @@ class CorpFinances extends Command //Setup the Finances container $finance = new FinanceHelper(); - //Get the esi configuration - $config = config('esi'); - //Get the corporations who have registered for structure markets $structures = CorpMarketStructure::all(); diff --git a/app/Console/Commands/Structures/GetStructures.php b/app/Console/Commands/Structures/GetStructures.php index 71c79aef3..3cdafcbed 100644 --- a/app/Console/Commands/Structures/GetStructures.php +++ b/app/Console/Commands/Structures/GetStructures.php @@ -8,10 +8,6 @@ use Log; //Library use App\Library\Structures\StructureHelper; use App\Library\Esi\Esi; -use Seat\Eseye\Cache\NullCache; -use Seat\Eseye\Configuration; -use Seat\Eseye\Containers\EsiAuthentication; -use Seat\Eseye\Eseye; use Commands\Library\CommandHelper; //Job @@ -70,7 +66,7 @@ class GetStructuresCommand extends Command $structures = null; //ESI Scope Check - $esiHelper = new Esi(); + $esiHelper = new Esi; $structureScope = $esiHelper->HaveEsiScope($charId, 'esi-universe.read_structures.v1'); $corpStructureScope = $esiHelper->HaveEsiScope($charId, 'esi-corporations.read_structures.v1'); @@ -87,13 +83,8 @@ class GetStructuresCommand extends Command //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, - ]); - //Setup the ESI variable - $esi = new Eseye($authentication); + //Create the esi authentication container + $esi = $esiHelper->SetupEsiAuthentication($token); //Set the current page $currentPage = 1; diff --git a/app/Http/Controllers/Contracts/ContractController.php b/app/Http/Controllers/Contracts/ContractController.php index 9f13b2b42..9cf8d1176 100644 --- a/app/Http/Controllers/Contracts/ContractController.php +++ b/app/Http/Controllers/Contracts/ContractController.php @@ -8,7 +8,7 @@ use DB; use Carbon\Carbon; //Libraries -use App\Library\Lookups\LookupHelper; +use App\Library\Lookups\NewLookupHelper; //use App\Library\Contracts\ContractHelper; //Models @@ -207,7 +207,7 @@ class ContractController extends Controller ]); //Delcare some class variables we will need - $lookup = new LookupHelper; + $lookup = new NewLookupHelper; $amount = 0.00; @@ -231,8 +231,11 @@ class ContractController extends Controller $characterId = auth()->user()->getId(); $characterName = auth()->user()->getName(); //Use the lookup helper in order to find the user's corporation id and name - $corporationId = $lookup->LookupCharacter($characterId); - $corporationName = $lookup->LookupCorporationName($corporationId); + $char = $looup->LookupCharacter($characterId, null); + $corporationId = $char->corporation_id; + //use the lookup helper in order to find the corporation's name from it's id. + $corp = $lookup->LookupCorporation($corporationId, null); + $corporationName = $corp->name; //Before saving a bid let's check to see if the user already placed a bid on the contract $found = Bid::where([ diff --git a/app/Http/Controllers/Moons/MoonsAdminController.php b/app/Http/Controllers/Moons/MoonsAdminController.php index 1a91f9486..1625bb307 100644 --- a/app/Http/Controllers/Moons/MoonsAdminController.php +++ b/app/Http/Controllers/Moons/MoonsAdminController.php @@ -20,7 +20,6 @@ use App\Models\MoonRent\MoonRental; //Library use App\Library\Moons\MoonCalc; use App\Library\Esi\Esi; -use App\Library\Lookups\LookupHelper; use App\Library\Lookups\NewLookupHelper; class MoonsAdminController extends Controller @@ -35,7 +34,6 @@ class MoonsAdminController extends Controller public function displayMoonsAdmin() { $this->middleware('role:Admin'); - $lookup = new LookupHelper; $lookupHelper = new NewLookupHelper; $contact = ''; $paid = ''; @@ -97,7 +95,6 @@ class MoonsAdminController extends Controller $rentalEnd = $rentalTemp->format('m-d'); //Set the contact name - //$contact = $lookup->CharacterName($rental->Contact); $contact = $lookupHelper->CharacterIdToName($rental->Contact); //Set up the renter whether it's W4RP or another corporation @@ -216,7 +213,7 @@ class MoonsAdminController extends Controller //Declare some static variables as needed $moonCalc = new MoonCalc; - $lookup = new LookupHelper; + $lookup = new NewLookupHelper; $paid = false; $system = null; $planet = null; @@ -260,7 +257,9 @@ class MoonsAdminController extends Controller } //Let's find the corporation and alliance information to ascertain whethery they are in Warped Intentions or another Legacy Alliance - $allianceId = $lookup->LookupCorporation($lookup->LookupCharacter($contact)); + $char = $lookup->LookupCharacter($contact, null); + $corp = $lookup->LookupCorporation($char->character_id, null); + $allianceId = $corp->alliance_id; //Create the date $date = new Carbon($request->date . '00:00:01'); diff --git a/app/Http/Controllers/Wiki/WikiController.php b/app/Http/Controllers/Wiki/WikiController.php index e6c05470a..b4f4ba73a 100644 --- a/app/Http/Controllers/Wiki/WikiController.php +++ b/app/Http/Controllers/Wiki/WikiController.php @@ -9,7 +9,7 @@ use DB; use Auth; //User Libraries -use App\Library\Lookups\LookupHelper; +use App\Library\Lookups\NewLookupHelper; //Models use App\Models\Doku\DokuGroupNames; @@ -27,7 +27,7 @@ class WikiController extends Controller public function purgeUsers() { //Declare helper classes - $helper = new LookupHelper; + $lookup = new NewLookupHelper; //Get all the users from the database $users = DokuUser::pluck('name')->all(); @@ -42,10 +42,19 @@ class WikiController extends Controller //If no name is found, then delete the user and have them start over with the wiki permissions $count = User::where(['name' => $user])->count(); if($count > 0) { + //Get the user from the database $charIdTemp = User::where(['name' => $user])->get(['character_id']); + + //Set the character id $charId = $charIdTemp[0]->character_id; - $corpId = $helper->LookupCharacter($charId); - $allianceId = $helper->LookupCorporation($corpId); + + //Set the corp id + $char = $lookup->LookupCharacter($charId, null); + $corpId = $char->corporation_id; + + //Set the alliance id + $corp = $lookup->LookupCorporation($corpId, null); + $allianceId = $corp->alliance_id; if(in_array($allianceId, $legacy) || in_array($allianceId, $renter) || $allianceId == 99004116) { //Do nothing diff --git a/app/Jobs/ProcessSendEveMailJob.php b/app/Jobs/ProcessSendEveMailJob.php index 530de1b5d..162441c39 100644 --- a/app/Jobs/ProcessSendEveMailJob.php +++ b/app/Jobs/ProcessSendEveMailJob.php @@ -10,10 +10,8 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Log; -//Seat stuff -use Seat\Eseye\Configuration; -use Seat\Eseye\Containers\EsiAuthentication; -use Seat\Eseye\Eseye; +//Library +use App\Library\Esi\Esi; use Seat\Eseye\Exceptions\RequestFailedException; //Models @@ -69,22 +67,17 @@ class ProcessSendEveMailJob implements ShouldQueue */ public function handle() { + //Declare some variables + $esiHelper = new Esi; + //Get the esi configuration $config = config('esi'); //Retrieve the token for main character to send mails from - $token = EsiToken::where(['character_id'=> 92626011])->first(); + $token = EsiToken::where(['character_id'=> $config['primary']])->first(); //Create the ESI authentication container - $config = config('esi'); - $authentication = new EsiAuthentication([ - 'client_id' => $config['client_id'], - 'secret' => $config['secret'], - 'refresh_token' => $token->refresh_token, - ]); - - //Setup the Eseye class - $esi = new Eseye($authentication); + $esi = $esiHelper->SetupEsiAuthentication($token); //Attemp to send the mail try { @@ -97,7 +90,7 @@ class ProcessSendEveMailJob implements ShouldQueue ]], 'subject' => $this->subject, ])->invoke('post', '/characters/{character_id}/mail/', [ - 'character_id'=> 92626011, + 'character_id'=> $config['primary'], ]); } catch(RequestFailedException $e) { Log::warning($e); diff --git a/app/Library/Assets/AssetHelper.php b/app/Library/Assets/AssetHelper.php index c4a2c90db..7a2ca05f2 100644 --- a/app/Library/Assets/AssetHelper.php +++ b/app/Library/Assets/AssetHelper.php @@ -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) diff --git a/app/Library/Contracts/EveContractsHelper.php b/app/Library/Contracts/EveContractsHelper.php index f790fefdf..078b74485 100644 --- a/app/Library/Contracts/EveContractsHelper.php +++ b/app/Library/Contracts/EveContractsHelper.php @@ -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([ diff --git a/app/Library/Esi/Esi.php b/app/Library/Esi/Esi.php index c55992ac7..3610cf0d7 100644 --- a/app/Library/Esi/Esi.php +++ b/app/Library/Esi/Esi.php @@ -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) { diff --git a/app/Library/Esi/Mail.php b/app/Library/Esi/Mail.php index b7bd7f49b..861ec7901 100644 --- a/app/Library/Esi/Mail.php +++ b/app/Library/Esi/Mail.php @@ -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, diff --git a/app/Library/Finances/Helper/FinanceHelper.php b/app/Library/Finances/Helper/FinanceHelper.php index 85dfebeef..eb4b53f04 100644 --- a/app/Library/Finances/Helper/FinanceHelper.php +++ b/app/Library/Finances/Helper/FinanceHelper.php @@ -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. diff --git a/app/Library/Lookups/LookupHelper.php b/app/Library/Lookups/LookupHelper.php deleted file mode 100644 index 62e62daab..000000000 --- a/app/Library/Lookups/LookupHelper.php +++ /dev/null @@ -1,328 +0,0 @@ -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, - ]); - } - } - } -} - -?> \ No newline at end of file diff --git a/app/Library/Structures/StructureHelper.php b/app/Library/Structures/StructureHelper.php index f292dc1de..a7a2f64fc 100644 --- a/app/Library/Structures/StructureHelper.php +++ b/app/Library/Structures/StructureHelper.php @@ -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);