diff --git a/app/Console/Commands/Assets/GetAssetsCommand.php b/app/Console/Commands/Assets/GetAssetsCommand.php index 89d7e7ace..e68b79263 100644 --- a/app/Console/Commands/Assets/GetAssetsCommand.php +++ b/app/Console/Commands/Assets/GetAssetsCommand.php @@ -7,7 +7,7 @@ use DB; use Log; //Job -use App\Jobs\ProcessAssetsJob; +use App\Jobs\Commands\Structures\ProcessAssetsJob; //Library use App\Library\Esi\Esi; @@ -48,49 +48,13 @@ class GetAssetsCommand extends Command */ public function handle() { - $assets = null; - $pages = 0; - //Create the command helper container $task = new CommandHelper('GetAssets'); //Add the entry into the jobs table saying the job is starting $task->SetStartStatus(); - //Setup the esi authentication container - $config = config('esi'); + ProcessAssetsJob::dispatch($charId, $corpId)->onQueue('assets'); - //Declare some variables - $charId = $config['primary']; - $corpId = 98287666; - - //ESI Scope Check - $esiHelper = new Esi(); - $assetScope = $esiHelper->HaveEsiScope($config['primary'], 'esi-assets.read_corporation_assets.v1'); - - if($assetScope == false) { - Log::critical("Scope check for esi-assets.read_corporation_assets.v1 failed."); - return null; - } - - //Get the refresh token from the database - $token = $esiHelper->GetRefreshToken($charId); - //Create the authentication container - $esi = $esiHelper->SetupEsiAuthentication($token); - - try { - $assets = $esi->page(1) - ->invoke('get', '/corporations/{corporation_id}/assets/', [ - 'corporation_id' => $corpId, - ]); - } catch (RequestFailedException $e) { - Log::critical("Failed to get asset list."); - return null; - } - - $pages = $assets->pages; - - for($i = 1; $i <= $pages; $i++) { - ProcessAssetsJob::dispatch($charId, $corpId, $i)->onQueue('assets'); - } + $task->SetStopStatus(); } } diff --git a/app/Console/Commands/Data/EmptyJumpBridges.php b/app/Console/Commands/Data/EmptyJumpBridges.php index f39c71ca1..2d1afdae8 100644 --- a/app/Console/Commands/Data/EmptyJumpBridges.php +++ b/app/Console/Commands/Data/EmptyJumpBridges.php @@ -5,13 +5,10 @@ namespace App\Console\Commands\Data; //Internal Library use Illuminate\Console\Command; -//Library -use Commands\Library\CommandHelper; - //Models use App\Models\Structure\Structure; use App\Models\Structure\Service; -use App\Models\Stock\Asset; +use App\Models\Structure\Asset; class EmptyJumpBridges extends Command { @@ -46,16 +43,8 @@ class EmptyJumpBridges extends Command */ public function handle() { - $task = new CommandHelper('EmptyJumpBridges'); - - //Add entry into the table saying the job is starting - $task->SetStartStatus(); - Structure::truncate(); Service::truncate(); Asset::truncate(); - - //Mark the job as finished - $task->SetStopStatus(); } } diff --git a/app/Console/Commands/Data/GetCorpsCommand.php b/app/Console/Commands/Data/GetCorpsCommand.php index b6c1e15da..f6bf9f3c0 100644 --- a/app/Console/Commands/Data/GetCorpsCommand.php +++ b/app/Console/Commands/Data/GetCorpsCommand.php @@ -4,7 +4,6 @@ namespace App\Console\Commands\Data; //Internal Library use Illuminate\Console\Command; -use Commands\Library\CommandHelper; //Models use App\Models\Corporation\AllianceCorp; @@ -47,11 +46,6 @@ class GetCorpsCommand extends Command */ public function handle() { - //Create the command helper container - $task = new CommandHelper('CorpJournal'); - //Add the entry into the jobs table saying the job is starting - $task->SetStartStatus(); - //Declare some variables $esiHelper = new Esi; @@ -82,8 +76,5 @@ class GetCorpsCommand extends Command $entry->name = $corpInfo->name; $entry->save(); } - - //Mark the job as finished - $task->SetStopStatus(); } } diff --git a/app/Console/Commands/Data/PurgeCorpMoonLedgers.php b/app/Console/Commands/Data/PurgeCorpMoonLedgers.php index a6cd82a40..56b7949f1 100644 --- a/app/Console/Commands/Data/PurgeCorpMoonLedgers.php +++ b/app/Console/Commands/Data/PurgeCorpMoonLedgers.php @@ -4,11 +4,6 @@ namespace App\Console\Commands\Data; //Internal Library use Illuminate\Console\Command; -use Carbon\Carbon; -use Log; - -//Library -use Commands\Library\CommandHelper; //Jobs use App\Jobs\Commands\Moons\PurgeMoonLedgerJob; @@ -46,11 +41,6 @@ class PurgeCorpMoonLedgers extends Command */ public function handle() { - $task = new CommandHelper('PurgeCorpLedgers'); - $task->SetStartStatus(); - PurgeMoonLedgerJob::dispatch(); - - $task->SetStopStatus(); } } diff --git a/app/Console/Commands/Eve/ItemPricesUpdateCommand.php b/app/Console/Commands/Eve/ItemPricesUpdateCommand.php index 84052629a..46c009bf1 100644 --- a/app/Console/Commands/Eve/ItemPricesUpdateCommand.php +++ b/app/Console/Commands/Eve/ItemPricesUpdateCommand.php @@ -3,10 +3,8 @@ namespace App\Console\Commands\Eve; use Illuminate\Console\Command; -use Log; //Library -use Commands\Library\CommandHelper; use App\Library\Moons\MoonCalc; //Job @@ -45,14 +43,9 @@ class ItemPricesUpdateCommand extends Command */ public function handle() { - $task = new CommandHelper('ItemPriceUpdate'); - $task->SetStartStatus(); - $moonHelper = new MoonCalc; $moonHelper->FetchNewPrices(); //ItemPricesUpdateJob::dispatch()->onQueue('default'); - - $task->SetStopStatus(); } } diff --git a/app/Console/Commands/Finances/HoldingFinancesCommand.php b/app/Console/Commands/Finances/HoldingFinancesCommand.php index 78290ab23..774d05cff 100644 --- a/app/Console/Commands/Finances/HoldingFinancesCommand.php +++ b/app/Console/Commands/Finances/HoldingFinancesCommand.php @@ -3,13 +3,11 @@ namespace App\Console\Commands\Finances; use Illuminate\Console\Command; -use Log; -use Commands\Library\CommandHelper; use App\Library\Finances\Helper\FinanceHelper; //Jobs -use App\Jobs\ProcessWalletJournalJob; +use App\Jobs\Commands\Finances\ProcessWalletJournalJob; class HoldingFinancesCommand extends Command { @@ -44,12 +42,6 @@ class HoldingFinancesCommand extends Command */ public function handle() { - //Create the command helper container - $task = new CommandHelper('HoldingFinances'); - - //Add the entry into the jobs table saying the job is starting - $task->SetStartStatus(); - //Setup the Finances container $finance = new FinanceHelper(); @@ -71,8 +63,5 @@ class HoldingFinancesCommand extends Command for($i = 1; $i <= $pages; $i++) { ProcessWalletJournalJob::dispatch(6, $config['primary'], $i)->onQueue('journal'); } - - //Mark the job as finished - $task->SetStopStatus(); } } diff --git a/app/Console/Commands/Finances/SovBillsCommand.php b/app/Console/Commands/Finances/SovBillsCommand.php index f0799623b..0bd3115da 100644 --- a/app/Console/Commands/Finances/SovBillsCommand.php +++ b/app/Console/Commands/Finances/SovBillsCommand.php @@ -3,13 +3,12 @@ namespace App\Console\Commands\Finances; use Illuminate\Console\Command; -use Log; -use Commands\Library\CommandHelper; + use App\Library\Finances\Helper\FinanceHelper; //Jobs -use App\Jobs\ProcessWalletJournalJob; +use App\Jobs\Commands\Finances\ProcessWalletJournalJob; //Models use App\Models\Esi\EsiToken; @@ -71,14 +70,7 @@ class SovBillsCommand extends Command $sovBill = new SovBillExpenses; $esiHelper = new Esi; $finance = new FinanceHelper(); - $lookup = new LookupHelper; - - //Create the command helper container - $task = new CommandHelper('SovBills'); - - //Add the entry into the jobs table saying the job is starting - $task->SetStartStatus(); - + $lookup = new LookupHelper; //Get the esi configuration $config = config('esi'); @@ -125,8 +117,5 @@ class SovBillsCommand extends Command } } } - - //Mark the job as finished - $task->SetStopStatus(); } } diff --git a/app/Console/Commands/Mining/MiningTaxesCommand.php b/app/Console/Commands/Mining/MiningTaxesInvoices.php similarity index 88% rename from app/Console/Commands/Mining/MiningTaxesCommand.php rename to app/Console/Commands/Mining/MiningTaxesInvoices.php index 22aefbce8..947a52e49 100644 --- a/app/Console/Commands/Mining/MiningTaxesCommand.php +++ b/app/Console/Commands/Mining/MiningTaxesInvoices.php @@ -1,10 +1,10 @@ SetStartStatus(); - //Get all of the characters who have registered structures for moon ledgers $miningChars = EsiScope::where([ 'scope' => 'esi-industry.read_corporation_mining.v1', @@ -83,8 +74,5 @@ class MoonsUpdateCommand extends Command //Fetch all of the corp ledgers with the job dispatch FetchMoonLedgerJob::dispatch($charId); } - - //Set task done status - $task->SetStopStatus(); } } diff --git a/app/Console/Commands/RentalMoons/AllianceRentalMoonInvoiceCreationCommand.php b/app/Console/Commands/RentalMoons/AllianceRentalMoonInvoiceCreationCommand.php index 2d57b6100..3424a1d81 100644 --- a/app/Console/Commands/RentalMoons/AllianceRentalMoonInvoiceCreationCommand.php +++ b/app/Console/Commands/RentalMoons/AllianceRentalMoonInvoiceCreationCommand.php @@ -4,12 +4,8 @@ namespace App\Console\Commands\RentalMoons; //Internal Library use Illuminate\Console\Command; -use Log; use Carbon\Carbon; -//Library -use Commands\Library\CommandHelper; - //Jobs use App\Jobs\Commands\RentalMoons\SendMoonRentalPaymentReminderJob; use App\Jobs\Commands\RentalMoons\UpdateMoonRentalPaidState; @@ -47,17 +43,10 @@ class AllianceRentalMoonInvoiceCreationCommand extends Command */ public function handle() { - //Set the task as started - $task = new CommandHelper('AllianceRentalInvoice'); - $task->SetStartStatus(); - //Send the job for the invoice creation command SendMoonRentalPaymentReminderJob::dispatch()->delay(Carbon::now()->addSeconds(10)); //Update the paid state for the moons UpdateMoonRentalPaidState::dispatch()->delay(Carbon::now()->addSeconds(600)); - - //Set the task as stopped - $task->SetStopStatus(); } } diff --git a/app/Console/Commands/RentalMoons/AllianceRentalMoonUpdatePricingCommand.php b/app/Console/Commands/RentalMoons/AllianceRentalMoonUpdatePricingCommand.php index 086ed952c..9ebad1db7 100644 --- a/app/Console/Commands/RentalMoons/AllianceRentalMoonUpdatePricingCommand.php +++ b/app/Console/Commands/RentalMoons/AllianceRentalMoonUpdatePricingCommand.php @@ -4,10 +4,6 @@ namespace App\Console\Commands\RentalMoons; //Internal Library use Illuminate\Console\Command; -use Log; - -//Library -use Commands\Library\CommandHelper; //Job use App\Jobs\Commands\RentalMoons\UpdateMoonRentalPrice; @@ -45,12 +41,6 @@ class AllianceRentalMoonUpdatePricingCommand extends Command */ public function handle() { - //Setup the task handler - $task = new CommandHelper('AllianceRentalMoonPriceUpdater'); - $task->SetStartStatus(); - UpdateMoonRentalPrice::dispatch(); - - $task->SetStopStatus(); } } diff --git a/app/Console/Commands/Structures/GetStructuresCommand.php b/app/Console/Commands/Structures/GetStructuresCommand.php index f4b4946b4..3289076bb 100644 --- a/app/Console/Commands/Structures/GetStructuresCommand.php +++ b/app/Console/Commands/Structures/GetStructuresCommand.php @@ -3,22 +3,9 @@ namespace App\Console\Commands\Structures; use Illuminate\Console\Command; -use Log; - -//Library -use App\Library\Structures\StructureHelper; -use App\Library\Esi\Esi; -use Commands\Library\CommandHelper; -use Seat\Eseye\Exceptions\RequestFailedException; //Job -use App\Jobs\ProcessStructureJob; - -//Models -use App\Models\Esi\EsiScope; -use App\Models\Esi\EsiToken; -use App\Models\Structure\Structure; -use App\Models\Structure\Service; +use App\Jobs\Commands\Structures\ProcessStructureJob; class GetStructuresCommand extends Command { @@ -53,69 +40,14 @@ class GetStructuresCommand extends Command */ public function handle() { - //Create the command helper container - $task = new CommandHelper('GetStructures'); - //Add the entry into the jobs table saying the job is starting - $task->SetStartStatus(); - //Get the esi config $config = config('esi'); //Declare some variables $charId = $config['primary']; $corpId = 98287666; - $sHelper = new StructureHelper($charId, $corpId); - $structures = null; - //ESI Scope Check - $esiHelper = new Esi; - $structureScope = $esiHelper->HaveEsiScope($charId, 'esi-universe.read_structures.v1'); - $corpStructureScope = $esiHelper->HaveEsiScope($charId, 'esi-corporations.read_structures.v1'); - - //Check scopes - if($structureScope == false || $corpStructureScope == false) { - if($structureScope == false) { - Log::critical("Scope check for esi-universe.read_structures.v1 has failed."); - } - if($corpStructureScope == false) { - Log::critical("Scope check for esi-corporations.read_structures.v1 has failed."); - } - return null; - } - - //Get the refresh token from the database - $token = $esiHelper->GetRefreshToken($charId); - //Create the esi authentication container - $esi = $esiHelper->SetupEsiAuthentication($token); - - //Set the current page - $currentPage = 1; - //Set our default total pages, and we will refresh this later - $totalPages = 1; - - //Try to get the ESI data - try { - $structures = $esi->page($currentPage) - ->invoke('get', '/corporations/{corporation_id}/structures/', [ - 'corporation_id' => $corpId, - ]); - } catch (RequestFailedException $e) { - Log::critical("Failed to get structure list."); - return null; - } - - //Get the total number of pages of all the structures - $totalPages = $structures->pages; - - //Truncate the structures and the structure services in order to prepare to put new structures in the database - Structure::truncate(); - Service::truncate(); - - for($i = 1; $i <= $totalPages; $i++) { - ProcessStructureJob::dispatch($charId, $corpId, $currentPage)->onQueue('structures'); - } - - //Mark the job as finished - $task->SetStopStatus(); + //Dispatch the job to be done when the application has time + ProcessStructureJob::dispatch($charId, $corpId); } } diff --git a/app/Console/Commands/SystemRental/SystemRentalCommand.php b/app/Console/Commands/SystemRental/SystemRentalCommand.php index f7ad23dfd..476a9f734 100644 --- a/app/Console/Commands/SystemRental/SystemRentalCommand.php +++ b/app/Console/Commands/SystemRental/SystemRentalCommand.php @@ -7,10 +7,7 @@ use Illuminate\Console\Command; use Carbon\Carbon; //Jobs -use App\Jobs\ProcessSendEveMailJob; - -//Library -use Command\Library\CommandHelper; +use App\Jobs\Commands\Eve\ProcessSendEveMailJob; //Models use App\Models\Rentals\RentalSystem; @@ -49,11 +46,6 @@ class SystemRentalCommand extends Command */ public function handle() { - //Create the new command helper container - $task = new CommandHelper('SystemRentalMailer'); - //Add the entry into the jobs table saying the job has started - $task->SetStartStatus(); - //Create other variables $body = null; $delay = 30; @@ -104,10 +96,6 @@ class SystemRentalCommand extends Command //After the mail is dispatched, save the sent mail record $this->SaveSentRecord($config['primary'], $subject, $body, (int)$contact->contact_id, 'character'); } - - //Mark the job as finished - $task->SetStopStatus(); - } private function TotalizeCost($systems) { diff --git a/app/Http/Controllers/Contracts/SupplyChainController.php b/app/Http/Controllers/Contracts/SupplyChainController.php index 6664e54bc..0ae97e37d 100644 --- a/app/Http/Controllers/Contracts/SupplyChainController.php +++ b/app/Http/Controllers/Contracts/SupplyChainController.php @@ -16,7 +16,7 @@ use App\Models\Contracts\SupplyChainBid; use App\Models\Contracts\SupplyChainContract; //Jobs -use App\Jobs\ProcessSendEveMailJob; +use App\Jobs\Commands\Eve\ProcessSendEveMailJob; class SupplyChainController extends Controller { diff --git a/app/Http/Controllers/Logistics/StructureRequestController.php b/app/Http/Controllers/Logistics/StructureRequestController.php index 9f3f88997..ec5bacd86 100644 --- a/app/Http/Controllers/Logistics/StructureRequestController.php +++ b/app/Http/Controllers/Logistics/StructureRequestController.php @@ -9,7 +9,7 @@ use Log; use Carbon\Carbon; //Jobs -use App\Jobs\ProcessSendEveMailJob; +use App\Jobs\Commands\Eve\ProcessSendEveMailJob; //Library Helpers use App\Library\Lookups\LookupHelper; diff --git a/app/Http/Controllers/Moons/MoonsAdminController.php b/app/Http/Controllers/Moons/MoonsAdminController.php index 751936023..185aeaa5d 100644 --- a/app/Http/Controllers/Moons/MoonsAdminController.php +++ b/app/Http/Controllers/Moons/MoonsAdminController.php @@ -25,7 +25,7 @@ use App\Library\Esi\Esi; use App\Library\Lookups\LookupHelper; //Jobs -use App\Jobs\ProcessSendEveMailJob; +use App\Jobs\Commands\Eve\ProcessSendEveMailJob; class MoonsAdminController extends Controller { diff --git a/app/Http/Controllers/Moons/MoonsController.php b/app/Http/Controllers/Moons/MoonsController.php index a06365f18..460cb02dc 100644 --- a/app/Http/Controllers/Moons/MoonsController.php +++ b/app/Http/Controllers/Moons/MoonsController.php @@ -23,7 +23,7 @@ use App\Library\Moons\MoonCalc; use App\Library\Lookups\LookupHelper; //Jobs -use App\Jobs\ProcessSendEveMailJob; +use App\Jobs\Commands\Eve\ProcessSendEveMailJob; class MoonsController extends Controller { diff --git a/app/Jobs/ProcessSendEveMailJob.php b/app/Jobs/Commands/Eve/ProcessSendEveMailJob.php similarity index 99% rename from app/Jobs/ProcessSendEveMailJob.php rename to app/Jobs/Commands/Eve/ProcessSendEveMailJob.php index b6f246791..3dacacbaf 100644 --- a/app/Jobs/ProcessSendEveMailJob.php +++ b/app/Jobs/Commands/Eve/ProcessSendEveMailJob.php @@ -1,6 +1,6 @@ charId = $charId; $this->corpId = $corpId; - $this->page = $page; //Set the connection for the job $this->connection = 'redis'; @@ -55,24 +48,30 @@ class ProcessStructureJob implements ShouldQueue /** * Execute the job. - * The job's task is to get all of the information for a particular structure - * and store it in the database. This task can take a few seconds because of the ESI - * calls required to store the information. We leave this type of job up to the queue - * in order to take the load off of the cron job. + * The job's duty is to get all of the corporation's moon mining observers, + * then store them in the database. * * @return void */ public function handle() { + //Declare variables $sHelper = new StructureHelper($this->charId, $this->corpId); - $structures = $sHelper->GetStructuresByPage($this->page); + /** + * Remove the current observers from the database. + */ - foreach($structures as $structure) { - $sHelper->ProcessStructure($structure); - } + /** + * Create the esi call to get the current observers + */ - //After the job is completed, delete the job - $this->delete(); + /** + * Add the current observers in the database + */ + + /** + * Cleanup + */ } } diff --git a/app/Jobs/Commands/MiningTaxes/MailMiningTaxesInvoiceJob.php b/app/Jobs/Commands/MiningTaxes/MailMiningTaxesInvoiceJob.php new file mode 100644 index 000000000..08de80d30 --- /dev/null +++ b/app/Jobs/Commands/MiningTaxes/MailMiningTaxesInvoiceJob.php @@ -0,0 +1,34 @@ +connection = 'redis'; + + $this->charId = $charId; + $this->corpId = $corpId; + $this->currentPage = 1; + $this->totalPages = 1; + + $this->config = config('esi'); + } + + /** + * Execute the job. + * The job's task is to get all of the information for all of the assets in + * a structure and store them in the database. This task can take a few seconds + * therefore we want the Horizon job queue to take care of the request rather + * than the cronjob. + * + * @return void + */ + public function handle() + { + //Declare variables + $esiHelper = new Esi; + $aHelper = new AssetHelper($this->charId, $this->corpId); + + //ESI Scope Check + $assetScope = $esiHelper->HaveEsiScope($this->config['primary'], 'esi-assets.read_corporation_assets.v1'); + + if($assetScope == false) { + Log::critical("Scope check for esi-assets.read_corporations_assets.v1 has failed in ProcessAssetsJob"); + return null; + } + + //Truncate the Asset data from the table + + //Get the refresh token from the database + $token = $esiHelper->GetRefreshToken($this->charId); + //Create the authentication container + $esi = $esiHelper->SetupEsiAuthentication($token); + + try { + $assets = $esi->page($this->currentPage) + ->invoke('get', '/corporations/{corporation_id}/assets/', [ + 'corporation_id' => $this->corpId, + ]); + } catch(RequestFailedException $e) { + Log::critical("Failed to get asset list in ProcessAssetsJob"); + return null; + } + + //Set the total number of pages + $this->totalPages = $assets->pages; + + //Do this while the total pages is not completed + do { + if($currentPage > 1) { + try { + $assets = $esi->page($this->currentPage) + ->invoke('get', '/corporations/{corporation_id}/assets/', [ + 'corporation_id' => $this->corpId, + ]); + } catch(RequestFailedException $e) { + Log::critical("Failed to get asset list on page " . $this->currentPage . " in ProcessAssetsJob"); + return null; + } + } + + //Cycle through the assets, and attempt to store them. + foreach($assets as $asset) { + //if the asset is in one of the locations we want, then store + //or update the asset + if(in_array($asset->location_flag, $this->location_array)) { + //Attempt to store the asset + $aHelper->StoreNewAsset($asset); + } + } + + //Increment the current page before doing the loop again + $this->currentPage++; + } while($this->currentPage <= $this->totalPages); + + //Once all the data is stored and updated, purge stale data + $aHelper->PurgeStaleData(); + } +} diff --git a/app/Jobs/Commands/Structures/ProcessStructureJob.php b/app/Jobs/Commands/Structures/ProcessStructureJob.php new file mode 100644 index 000000000..7d7d26dc6 --- /dev/null +++ b/app/Jobs/Commands/Structures/ProcessStructureJob.php @@ -0,0 +1,143 @@ +connection = 'redis'; + + $this->charId = $charId; + $this->corpId = $corpId; + $this->currentPage = 1; + $this->totalPages = 1; + } + + /** + * Execute the job. + * The job's task is to get all of the information for a particular structure + * and store it in the database. This task can take a few seconds because of the ESI + * calls required to store the information. We leave this type of job up to the queue + * in order to take the load off of the cron job. + * + * @return void + */ + public function handle() + { + //Declare variables + $config = config('esi'); + $sHelper = new StructureHelper($this->charId, $this->corpId); + $structures = null; + + //ESI Scope Check + $esiHelper = new Esi; + $structureScope = $esiHelper->HaveEsiScope($charId, 'esi-universe.read_structures.v1'); + $corpStructureScope = $esiHelper->HaveEsiScope($charId, 'esi-corporations.read_structures.v1'); + + //Check scopes + if($structureScope == false || $corpStructureScope == false) { + if($structureScope == false) { + Log::critical("Scope check for esi-universe.read_structures.v1 has failed."); + } + if($corpStructureScope == false) { + Log::critical("Scope check for esi-corporations.read_structures.v1 has failed."); + } + return null; + } + + //Get the refresh token from the database + $token = $esiHelper->GetRefreshToken($this->charId); + //Create the esi authentication container + $esi = $esiHelper->SetupEsiAuthentication($token); + + //Attempt to get the ESI data + try { + $structures = $esi->page($this->currentPage) + ->invoke('get', '/corporations/{corporation_id}/structures/', [ + 'corporation_id' => $this->corpId, + ]); + } catch (RequestFailedException $e) { + Log::critical("Failed to get structure list in ProcessStructureJob"); + return null; + } + + $this->totalPages = $structures->pages; + + //Truncate the structures and the structure services in order to add the latest data + Structure::truncate(); + Service::truncate(); + + do { + if($this->currentPage > 1) { + try { + $structures = $esi->page($this->currentPage) + ->invoke('get', '/corporations/{corporation_id}/structures/', [ + 'corporation_id' => $this->corpId, + ]); + } catch(RequestFailedException $e) { + Log::critical("Failed to get structure list on page" . $this->currentPage . " in ProcessStructureJob."); + return null; + } + } + + //For each set of data, process the data + foreach($structures as $structure) { + $sHelper->ProcessStructure($structure); + } + //Increment the current page + $this->currentPage++; + } while($this->currentPage <= $this->totalPages); + + //After the job is completed, delete the job + $this->delete(); + } +} diff --git a/app/Jobs/Commands/SupplyChain/EndSupplyChainContractJob.php b/app/Jobs/Commands/SupplyChain/EndSupplyChainContractJob.php index 04bf57196..3bab6f07a 100644 --- a/app/Jobs/Commands/SupplyChain/EndSupplyChainContractJob.php +++ b/app/Jobs/Commands/SupplyChain/EndSupplyChainContractJob.php @@ -18,7 +18,7 @@ use App\Models\Contracts\SupplyChainBid; use App\Models\Contracts\SupplyChainContract; //Jobs -use App\Jobs\ProcessSendEveMailJob; +use App\Jobs\Commands\Eve\ProcessSendEveMailJob; class EndSupplyChainContractJob implements ShouldQueue { diff --git a/app/Jobs/ProcessAssetsJob.php b/app/Jobs/ProcessAssetsJob.php deleted file mode 100644 index 3c1b21d82..000000000 --- a/app/Jobs/ProcessAssetsJob.php +++ /dev/null @@ -1,100 +0,0 @@ -charId = $charId; - $this->corpId = $corpId; - $this->page = $page; - - //Set the connection for the job - $this->connection = 'redis'; - } - - /** - * Execute the job. - * The job's task is to get all fo the information for all of the assets in - * a structure and store them in the database. This task can take a few seconds - * therefore we want the Horizon job queue to take care of the request rather - * than the cronjob. - * - * @return void - */ - public function handle() - { - //Declare the asset helper - $aHelper = new AssetHelper($this->charId, $this->corpId, $this->page); - - //Get a page of assets - $assets = $aHelper->GetAssetsByPage(); - - //Cycle through the assets, and attmept to store them. - foreach($assets as $asset) { - //If the asset is in one of the locations we want, then store - //or update the asset - if(in_array($asset->location_flag, $this->location_array)) { - //Attempt to store the asset - $aHelper->StoreNewAsset($asset); - } - } - - //Purge Stale Data - $aHelper->PurgeStaleData(); - } -} diff --git a/app/Library/Assets/AssetHelper.php b/app/Library/Assets/AssetHelper.php index 3c9d8db1e..707b66f84 100644 --- a/app/Library/Assets/AssetHelper.php +++ b/app/Library/Assets/AssetHelper.php @@ -13,24 +13,22 @@ use Seat\Eseye\Exceptions\RequestFailedException; //Models use App\Models\Jobs\JobStatus; -use App\Models\Stock\Asset; +use App\Models\Structure\Asset; class AssetHelper { private $charId; private $corpId; - private $page; - public function __construct($char, $corp, $pg = null) { + public function __construct($char, $corp) { $this->charId = $char; $this->corpId = $corp; - $this->page = $pg; - } + } /** * Get Assets By Page in order to store in the database */ - public function GetAssetsByPage() { + public function GetAssetsByPage($page) { //Declare the variable for the esi helper $esiHelper = new Esi; diff --git a/app/Library/Esi/Esi.php b/app/Library/Esi/Esi.php index 1ff4483e0..d31481dd0 100644 --- a/app/Library/Esi/Esi.php +++ b/app/Library/Esi/Esi.php @@ -10,7 +10,7 @@ use App\Models\Esi\EsiToken; use App\Models\Esi\EsiScope; //Jobs -use App\Jobs\ProcessSendEveMailJob; +use App\Jobs\Commands\Eve\ProcessSendEveMailJob; //Seat Stuff use Seat\Eseye\Cache\NullCache; diff --git a/app/Models/Eve/EveRegion.php b/app/Models/Eve/EveRegion.php deleted file mode 100644 index a67d0b4dd..000000000 --- a/app/Models/Eve/EveRegion.php +++ /dev/null @@ -1,24 +0,0 @@ -id(); + $table->unsignedBigInteger('character_id'); + $table->string('character_name'); + $table->unsignedBigInteger('invoice_id'); + $table->float('invoice_amount'); + $table->dateTime('date_issued'); + $table->dateTime('date_due'); + $table->enum('status', [ + 'Pending', + 'Paid', + 'Late', + 'Paid Late', + 'Deferred', + ]); + $table->timestamps(); + }); + + Schema::create('alliance_mining_tax_observers', function (Blueprint $table) { + $table->id(); + $table->dateTime('last_updated'); + $table->unsignedBigInteger('observer_id'); + $table->string('observer_type'); $table->timestamps(); }); Schema::create('alliance_mining_tax_ledgers', function (Blueprint $table) { $table->id(); + $table->unsignedBigInteger('character_id'); + $table->dateTime('last_updated'); + $table->unsignedBigInteger('type_id'); + $table->string('ore_name'); + $table->unsignedBigInteger('quantity'); $table->timestamps(); }); Schema::create('alliance_mining_tax_payments', function (Blueprint $table) { $table->id(); + $table->unsignedBigInteger('character_id'); + $table->string('character_name'); + $table->unsignedBigInteger('invoice_id'); + $table->float('invoice_amount'); + $table->float('payment_amount'); + $table->dateTime('payment_date'); + $table->enum('status', [ + 'Pending', + 'Accepted', + 'Rejected', + ]); $table->timestamps(); }); }