From d3db43de8bdd43a23709a6f46f0d32496bf1fc15 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Tue, 16 Feb 2021 06:10:01 +0900 Subject: [PATCH] codebase --- .../MiningTaxes/MiningTaxesObservers.php | 47 ++++++++++++++++++- .../FetchMiningTaxesObserversJob.php | 2 - 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/MiningTaxes/MiningTaxesObservers.php b/app/Console/Commands/MiningTaxes/MiningTaxesObservers.php index c4daf5292..a793a526c 100644 --- a/app/Console/Commands/MiningTaxes/MiningTaxesObservers.php +++ b/app/Console/Commands/MiningTaxes/MiningTaxesObservers.php @@ -48,9 +48,54 @@ class MiningTaxesObservers extends Command //Set the task as started $task->SetStartStatus(); + //Declare variables $config = config('esi'); + $lookup = new LookupHelper; + $esiHelper = new Esi; + + //Check for the esi scope + if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1') || !$esiHelper->HaveEsiScope($config['corporation'], 'esi-universe.read_structures.v1')) { + Log::critical('Esi scopes were not found for FetchMiningTaxesObserversJob.'); + return; + } + + //Get the refresh token for the character + $refreshToken = $esiHelper->GetRefreshToken($this->charId); + //Get the esi variable + $esi = $esiHelper->SetupEsiAuthentication($refreshToken); + + try { + $response = $esi->invoke('get', '/corporations/{corporation_id}/mining/observers', [ + 'corporation_id' => $this->corpId, + ]); + } catch(RequestFailedException $e) { + Log::critical("Failed to get moon observers in FetchMiningTaxesObservers"); + Log::critical($e); + } + + $resp = json_decode($response, false); + + dd($resp); + + //Run through the mining observers, and add them to the database + foreach($resp as $observer) { + + Observer::updateOrInsert([ + 'observer_id' => $observer->observer_id, + ], [ + 'observer_id' => $observer->observer_id, + 'observer_type' => $observer->observer_type, + 'last_updated' => $observer->last_updated, + ]); + } + + /** + * Cleanup stale data that hasn't been updated in at least 1 week. + */ + $date = Carbon::now()->subDay(7); + Observer::where('updated_at', '<', $date)->delete(); + - FetchMiningTaxesObserversJob::dispatch($config['primary'], $config['corporation'])->onQueue('miningtaxes'); $task->SetStopStatus(); diff --git a/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesObserversJob.php b/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesObserversJob.php index 53b13adde..a325e750b 100644 --- a/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesObserversJob.php +++ b/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesObserversJob.php @@ -14,7 +14,6 @@ use Log; use Seat\Eseye\Exceptions\RequestFailedException; use App\Library\Esi\Esi; use App\Library\Helpers\LookupHelper; -use App\Library\Helpers\StructureHelper; //App Models use App\Models\MiningTax\Observer; @@ -67,7 +66,6 @@ class FetchMiningTaxesObserversJob implements ShouldQueue public function handle() { //Declare variables - $sHelper = new StructureHelper($this->charId, $this->corpId); $lookup = new LookupHelper; $esiHelper = new Esi;