From ec556cfc2951f555c5d763af01c90d56fc17ea62 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Sat, 4 May 2019 23:24:55 -0500 Subject: [PATCH] pi transactions --- app/Console/Commands/pitransactions.php | 15 +-- app/Jobs/ProcessWallettransactionJob.php | 4 +- app/Library/Finances/Helper/FinanceHelper.php | 110 ++---------------- .../Jobs/JobProcessWalletTransaction.php | 1 - 4 files changed, 18 insertions(+), 112 deletions(-) diff --git a/app/Console/Commands/pitransactions.php b/app/Console/Commands/pitransactions.php index fd4d3a389..5516457d3 100644 --- a/app/Console/Commands/pitransactions.php +++ b/app/Console/Commands/pitransactions.php @@ -56,17 +56,10 @@ class PiTransactionsCommand extends Command //Setup the Finances container $finance = new FinanceHelper(); - //Get the total pages for the transactions - $pages = $finance->GetTransactionPageCount(3, 94415555); - dd($pages); - //Dispatch a single job for each page to process - for($i = 1; $i <= $pages; $i++) { - $job = new JobProcessWalletTransaction; - $job->division = 3; - $job->charId = 94415555; - $job->page = $i; - ProcessWalletTransactionJob::dispatch($job); - } + $job = new JobProcessWalletTransaction; + $job->division = 3; + $job->charId = 94415555; + ProcessWalletTransactionJob::dispatch($job); //Mark the job as finished $task->SetStopStatus(); diff --git a/app/Jobs/ProcessWallettransactionJob.php b/app/Jobs/ProcessWallettransactionJob.php index 09d4b318d..4e0bcf28d 100644 --- a/app/Jobs/ProcessWallettransactionJob.php +++ b/app/Jobs/ProcessWallettransactionJob.php @@ -15,7 +15,7 @@ use App\Library\Finances\Helper\FinanceHelper; //App Models use App\Models\Jobs\JobProcessWalletTransaction; -class ProcessWallettransactionJob implements ShouldQueue +class ProcessWalletTransactionJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; @@ -57,7 +57,7 @@ class ProcessWallettransactionJob implements ShouldQueue //Declare the class variables $finance = new FinanceHelper(); - $finance->GetWalletTransactionPage($this->division, $this->charId, $this->page); + $finance->GetWalletTransaction($this->division, $this->charId); //After the job is completed, delete the job $this->delete(); diff --git a/app/Library/Finances/Helper/FinanceHelper.php b/app/Library/Finances/Helper/FinanceHelper.php index 431e7efad..b612622b6 100644 --- a/app/Library/Finances/Helper/FinanceHelper.php +++ b/app/Library/Finances/Helper/FinanceHelper.php @@ -105,103 +105,22 @@ class FinanceHelper { //Create the esi class varialble $esi = new Eseye($authentication); - - //Set our current page to 1 which is the one we are starting on. - $currentPage = 1; - //Set our default total pages to 1 in case our try section fails out. - $totalPages = 1; - //If more than one page is found, decode the first set of wallet entries, then call for the next pages - do { - //Call the first page of the wallet journal, as we are always going to get at least one page. - //If we have more pages, then we will continue through the while loop. - try { - $journals = $esi->page($currentPage) - ->invoke('get', '/corporations/{corporation_id}/wallets/{division}/transactions/', [ - 'corporation_id' => 98251577, - 'division' => 3, - ]); - } catch(RequestFailedException $e) { - return $e->getEsiResponse(); - } - - //Set the total pages we need to cycle through. - $totalPages = $journals->pages; - //Decode the wallet from json into an array - $wallet = json_decode($journals->raw, true); - //For each journal entry, attempt to store it in the database. - //The PutWalletJournal function checks to see if it's already in the database. - foreach($wallet as $entry) { - if($division == 3 && $charId == 94415555) { - if(in_array($entry['type_id'], $pi_items, false)) { - $pi = new PISale(); - $pi->InsertPISale($entry, 98287666); - } - } - } - - //Increment the current page we are on. - $currentPage++; - //Continue looping through the do while loop until the current page is greater than or equal to the total pages. - } while ($currentPage < $totalPages); - } - - public function GetWalletTransactionPage($division, $charId, $page = 1) { - //Declare the lookup class helper - $lookups = new LookupHelper; - - //Setup array for PI items - $pi_items = $this->GetPIMaterialsArray(); - - //Get the ESI refresh token for the corporation to add new wallet journals into the database - $tokenData = $this->TokenInfo($charId); - $token = $tokenData['token']; - $scope = $tokenData['scope']; - - //If the token is not found, send the user an eve mail, and just exit out of the function - if($this->TokenNotFound($token, $scope, $charId)) { - printr("Token not found\n"); - return null; + //Get the entries of the journal for transactions + try { + $journals = $esi->page($currentPage) + ->invoke('get', '/corporations/{corporation_id}/wallets/{division}/transactions/', [ + 'corporation_id' => 98251577, + 'division' => 3, + ]); + } catch(RequestFailedException $e) { + return $e->getEsiResponse(); } - //Reference to see if the character is in our look up table for corporations and characters - $corpId = $lookups->LookupCharacter($charId); + //Decode the wallet from json into an array + $wallet = json_decode($journals->raw, true); - //Create an ESI authentication container - $config = config('esi'); - $authentication = new EsiAuthentication([ - 'client_id' => $config['client_id'], - 'secret' => $config['secret'], - 'refresh_token' => $token[0]->refresh_token, - ]); - - //Create the esi class varialble - $esi = new Eseye($authentication); - - //Set our current page to 1 which is the one we are starting on. - $currentPage = 1; - //Set our default total pages to 1 in case our try section fails out. - $totalPages = 1; - - //If more than one page is found, decode the first set of wallet entries, then call for the next pages - do { - //Call the first page of the wallet journal, as we are always going to get at least one page. - //If we have more pages, then we will continue through the while loop. - try { - $journals = $esi->page($currentPage) - ->invoke('get', '/corporations/{corporation_id}/wallets/{division}/transactions/', [ - 'corporation_id' => 98251577, - 'division' => 3, - ]); - } catch(RequestFailedException $e) { - return $e->getEsiResponse(); - } - - //Set the total pages we need to cycle through. - $totalPages = $journals->pages; - //Decode the wallet from json into an array - $wallet = json_decode($journals->raw, true); - //For each journal entry, attempt to store it in the database. + //For each transactional entry, attempt to store it in the database. //The PutWalletJournal function checks to see if it's already in the database. foreach($wallet as $entry) { if($division == 3 && $charId == 94415555) { @@ -211,11 +130,6 @@ class FinanceHelper { } } } - - //Increment the current page we are on. - $currentPage++; - //Continue looping through the do while loop until the current page is greater than or equal to the total pages. - } while ($currentPage < $totalPages); } public function GetWalletJournal($division, $charId) { diff --git a/app/Models/Jobs/JobProcessWalletTransaction.php b/app/Models/Jobs/JobProcessWalletTransaction.php index bd0e8a42d..be4277c1c 100644 --- a/app/Models/Jobs/JobProcessWalletTransaction.php +++ b/app/Models/Jobs/JobProcessWalletTransaction.php @@ -17,7 +17,6 @@ class JobProcessWalletTransaction extends Model protected $fillable = [ 'charId', 'division', - 'page', ]; }