From 083422047ce51e4db38071296c7af33fab0ac651 Mon Sep 17 00:00:00 2001 From: Christopher Mancuso Date: Thu, 24 Jun 2021 11:42:53 +0900 Subject: [PATCH] store operations form --- .../MiningTaxesAdminController.php | 9 ++--- app/Library/Helpers/StructureHelper.php | 35 ++++++++++++------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php b/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php index 0d293e48d..dde46d46b 100644 --- a/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php +++ b/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php @@ -88,10 +88,11 @@ class MiningTaxesAdminController extends Controller 'structure' => 'required', ]); - //Get the name of the structure from the table - $m = Observer::where([ - 'observer_id' => $request->structure, - ])->first(); + $config = config('esi'); + $sHelper = new StructureHelper($config['primary'], $config['corporation']); + + //Get the name of the structure from the database + $m = $sHelper->GetStructureInfo($request->structure); //Save the mining operation into the database $operation = new MiningOperation; diff --git a/app/Library/Helpers/StructureHelper.php b/app/Library/Helpers/StructureHelper.php index 23f9cb92c..c96d44da4 100644 --- a/app/Library/Helpers/StructureHelper.php +++ b/app/Library/Helpers/StructureHelper.php @@ -95,20 +95,31 @@ class StructureHelper { } } + /** + * Search for a structure in our own database, otherwise pull it from esi. + */ public function GetStructureInfo($structureId) { - try { - $info = $this->esi->invoke('get', '/universe/structures/{structure_id}/', [ - 'structure_id' => $structureId, - ]); - } catch(RequestFailedException $e) { - Log::warning("Failed to get structure information for structure with id " . $structureId); - Log::warning($e->getCode()); - Log::warning($e->getMessage()); - Log::warning($e->getEsiResponse()); - $info = null; - } + $info = Struture::where([ + 'structure_id' => $structureId, + ])->first(); - return $info; + if($info != null) { + return $info; + } else { + try { + $info = $this->esi->invoke('get', '/universe/structures/{structure_id}/', [ + 'structure_id' => $structureId, + ]); + } catch(RequestFailedException $e) { + Log::warning("Failed to get structure information for structure with id " . $structureId); + Log::warning($e->getCode()); + Log::warning($e->getMessage()); + Log::warning($e->getEsiResponse()); + return null; + } + + return $info; + } } private function UpdateExistingStructure($structure, $info) {