diff --git a/app/Library/Esi/Esi.php b/app/Library/Esi/Esi.php index 1e46906a4..ece005ddb 100644 --- a/app/Library/Esi/Esi.php +++ b/app/Library/Esi/Esi.php @@ -10,6 +10,7 @@ use Seat\Eseye\Cache\NullCache; use Seat\Eseye\Configuration; use Seat\Eseye\Containers\EsiAuthentication; use Seat\Eseye\Eseye; +use Seat\Eseye\Exceptions\RequestFailedException; /** * This class represents a few ESI helper functions for the program @@ -36,12 +37,29 @@ class Esi { return false; } + public function GetCharacterData($charId) { + $esi = new Eseye(); + try { + $character = $esi->invoke('get', '/characters/{character_id}/', [ + 'character_id' => $charId, + ]); + } catch(RequestFailedException $e) { + return null; + } + + return $character; + } + public function GetCharacterName($charId) { $esi = new Eseye(); - $character = $esi->invoke('get', '/characters/{character_id}/', [ - 'character_id' => $charId, - ]); - + try { + $character = $esi->invoke('get', '/characters/{character_id}/', [ + 'character_id' => $charId, + ]); + } catch(RequestFailedException $e) { + return null; + } + return $character->name; } @@ -54,12 +72,17 @@ class Esi { ]); //Create the esi container $esi = new Eseye($authentication); - $character = $esi->setQueryString([ - 'categories' => 'character', - 'language' => 'en-us', - 'search' => $name, - 'strict' => 'true', - ])->invoke('get', '/search/'); + 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); @@ -68,22 +91,31 @@ class Esi { public function FindCorporationId($charId) { $esi = new Eseye(); - $character = $esi->invoke('get', '/characters/{character_id}/', [ - 'character_id' => $charId, - ]); - + try { + $character = $esi->invoke('get', '/characters/{character_id}/', [ + 'character_id' => $charId, + ]); + } catch(RequestFailedException $e) { + return null; + } + return $character->corporation_id; } public function FindCorporationName($charId) { $esi = new Eseye(); - $character = $esi->invoke('get', '/characters/{character_id}/', [ - 'character_id' => $charId, - ]); - - $corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [ - 'corporation_id' => $character->corporation_id, - ]); + 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; + } + return $corporation->name; } diff --git a/app/Library/Esi/Mail.php b/app/Library/Esi/Mail.php index e22414ea8..0c39912b3 100644 --- a/app/Library/Esi/Mail.php +++ b/app/Library/Esi/Mail.php @@ -11,6 +11,7 @@ use Seat\Eseye\Cache\NullCache; use Seat\Eseye\Configuration; use Seat\Eseye\Containers\EsiAuthentication; use Seat\Eseye\Eseye; +use Seat\Eseye\Exceptions\RequestFailedException; class Mail { @@ -39,7 +40,7 @@ class Mail { ])->invoke('post', '/characters/{character_id}/mail/', [ 'character_id' => 93738489, ]); - } catch(\Seat\Eseye\Exceptions\RequestFailedException $e) { + } catch(RequestFailedException $e) { return $e->getEsiResponse(); } } diff --git a/app/Library/Finances/JumpBridgeTax.php b/app/Library/Finances/JumpBridgeTax.php index 6ddc79287..8991a7f25 100644 --- a/app/Library/Finances/JumpBridgeTax.php +++ b/app/Library/Finances/JumpBridgeTax.php @@ -80,6 +80,7 @@ class JumpBridgeTax { //Make an array for corporations, and amounts $corps = array(); $amounts = array(); + $esi = new Esi(); //Get all of the parties which have utilized the jump bridge $parties = DB::table('jump_bridge_journal') @@ -91,7 +92,19 @@ class JumpBridgeTax { //Run through each party and assign them into a corporation, then add the corporation to the corporation array if they don't //exist in the array. foreach($parties as $party) { + //If the entry in the database lookup table isn't found, add it. + if(!CharacterToCorporation::where(['character_id' => $party->first_party_id])->exists()) { + $character = $esi->GetCharacterData($party->first_party_id); + $corporation = $esi->GetCorporationData($character->corporation_id); + $char = new CharacterToCorporation; + $char->character_id = $party->first_party_id; + $char->character_name = $character->name; + $char->corporation_id = $character->corporation_id; + $char->corporation_name = $corporation->name; + $char->save(); + } + //Perform the lookup and add the user into the corps array, and the ammount to the amount array } } diff --git a/app/Library/Lookups/LookupHelper.php b/app/Library/Lookups/LookupHelper.php index e4557048b..8427d888e 100644 --- a/app/Library/Lookups/LookupHelper.php +++ b/app/Library/Lookups/LookupHelper.php @@ -166,7 +166,6 @@ class LookupHelper { ]); } } - } }