process structure job is complete. just need to make migrations

This commit is contained in:
2019-05-28 03:17:26 -05:00
parent c5039c3152
commit 414f35e353
3 changed files with 80 additions and 10 deletions

View File

@@ -81,9 +81,9 @@ class ProcessStructureJob implements ShouldQueue
$config = config('esi');
$token = EsiToken::where(['character_id' => 93738489])->get(['refresh_token']);
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'];
'secret' => $config['secret'];
'refresh_token' => $token[0]->refresh_token;
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
//Declare the esi variable
@@ -97,6 +97,15 @@ class ProcessStructureJob implements ShouldQueue
return null;
}
//Attempt to get the solar system name from ESI
try {
$solarName = $esi->invoke('get', '/universe/systems/{system_id}/', [
'system_id' => $info['solary_system_id'],
]);
} catch(RequestFailedException $e) {
$solarName = null;
}
//Record the structure information into the database
//Find if the structure exists
$found = Structure::where(['structure_id' => $this->structure['structure_id']])->get();
@@ -108,20 +117,85 @@ class ProcessStructureJob implements ShouldQueue
$structure->structure_name = $info['name'];
$structure->corporation_id = $info['owner_id'];
$structure->solar_system_id = $info['solar_system_id'];
$structure->solary_system_name = $solarName;
if(isset($info['type_id'])) {
$structure->type_id = $info['type_id'];
}
$structure->corporation_id = $this->structure['corporation_id'];
if(isset($this->structures['services'])) {
$structure->services = true;
} else {
$structure->services = false;
}
if(isset($this->structure['state_timer_start'])) {
$structure->state_timer_start = $this->DecodeDate($this->structure['state_timer_start']);
}
if(isset($this->structure['state_timer_end'])) {
$structure->state_timer_end = $this->DecodeDate($this->structure['state_timer_end']);
}
if(isset($this->structure['fuel_expires'])) {
$structure->fuel_expires = $this->structure['fuel_expires'];
}
$structure->profile_id = $this->structure['profile_id'];
$structure->position_x = $info['position']['x'];
$structure->position_y = $info['position']['y'];
$structure->position_z = $info['position']['z'];
$structure->fuel_expires = $this->structure['fuel_expires'];
$structure->next_reinforce_apply = $this->structure['']
if(isset($this->structure['next_reinforce_apply'])) {
$structure->next_reinforce_apply = $this->structure['next_reinforce_apply'];
}
if(isset($this->structure['next_reinforce_hour'])) {
$structure->next_reinforce_hour = $this->structure['next_reinforce_hour'];
}
if(isset($this->structure['next_reinforce_weekday'])) {
$structure->next_reinforce_weekday = $this->structure['next_reinforce_weekday'];
}
$structure->reinforce_hour = $this->structure['reinforce_hour'];
if(isset($this->structure['reinforce_weekday'])) {
$structure->reinforce_weekday = $this->structure['reinforce_weekday'];
}
if(isset($this->structure['unanchors_at'])) {
$structure->unanchors_at = $this->structure['unanchors_at'];
}
//If we set the structure services to true, let's save the services
if($structure->services == true) {
$this->StorestructureServices($this->structure['services'], $this->structure['structure_id']);
}
//Save the database record
$structure->save();
}
//Record the structure's services information into the database
}
private function StoreStructureServices($services, $structureId) {
foreach($services as $service) {
//Find the structure id and the name of the service to see if it exists
$found = Service::where([
'structure_id' => $structureId,
'name' => $service['name'],
])->get();
if(!$found) {
$new = new Service;
$new->structure_id = $structureId;
$new->name = $service['name'];
$new->state = $service['state'];
$new->save();
} else {
Service::where([
'structure_id' => $structureId,
'name' => $service['name'],
])->update([
'state' => $service['state'],
]);
}
}
}
private function DecodeDate($date) {
$esiHelper = new Esi();

View File

@@ -44,10 +44,6 @@ class StructureStockHelper {
$this->structureInfo = $structure;
}
public function StoreStructureInfo() {
}
}
?>

View File

@@ -30,7 +30,7 @@ class Structure extends Model
'type_id',
'corporation_id',
'services', //True or false on whether it has services which are held in a different table
'state'
'state',
'state_timer_start',
'state_timer_end',
'fuel_expires',