added primary keys to the new db tables
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Log;
|
||||
use DB;
|
||||
|
||||
//App Library
|
||||
use App\Library\Structures\StructureHelper;
|
||||
|
||||
@@ -8,41 +8,132 @@
|
||||
namespace App\Library\Structures\Helper;
|
||||
|
||||
//Internal Library
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Log;
|
||||
use DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
//Job
|
||||
use App\Jobs\ProcessStocksJob;
|
||||
//App Models
|
||||
use App\Models\Structure\Structure;
|
||||
use App\Models\Structure\Service;
|
||||
|
||||
//Library
|
||||
use App\Library\Esi\Esi;
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
|
||||
//Models
|
||||
use App\Models\Stock\StructureStock;
|
||||
|
||||
class StructureStockHelper {
|
||||
|
||||
private $scopeCheck;
|
||||
|
||||
private $structureInfo;
|
||||
|
||||
public function __construct($structure) {
|
||||
$esi = new Esi();
|
||||
$structureScope = $esi->HaveEsiScope($charId, 'esi-universe.read_structurs.v1');
|
||||
|
||||
if($structureScope == false) {
|
||||
$this->scopeCheck = false;
|
||||
public function StoreNewStructure($structure, $info, $solarName) {
|
||||
$struct = new Structure;
|
||||
$struct->structure_id = $structure->structure_id;
|
||||
$struct->structure_name = $info->name;
|
||||
$struct->corporation_id = $info->owner_id;
|
||||
$struct->solar_system_id = $info->solar_system_id;
|
||||
$struct->solary_system_name = $solarName;
|
||||
if(isset($info->type_id)) {
|
||||
$struct->type_id = $info->type_id;
|
||||
}
|
||||
$struct->corporation_id = $structure->corporation_id;
|
||||
if(isset($structure->services)) {
|
||||
$struct->services = true;
|
||||
} else {
|
||||
$this->scopeCheck = true;
|
||||
$struct->services = false;
|
||||
}
|
||||
if(isset($structure->state_timer_start)) {
|
||||
$struct->state_timer_start = $this->DecodeDate($structure->state_timer_start);
|
||||
}
|
||||
if(isset($structure->state_timer_end)) {
|
||||
$struct->state_timer_end = $this->DecodeDate($structure->state_timer_end);
|
||||
}
|
||||
if(isset($structure->fuel_expires)) {
|
||||
$struct->fuel_expires = $structure->fuel_expires;
|
||||
}
|
||||
$struct->profile_id = $structure->profile_id;
|
||||
$struct->position_x = $info->position->x;
|
||||
$struct->position_y = $info->position->y;
|
||||
$struct->position_z = $info->position->z;
|
||||
if(isset($structure->next_reinforce_apply)) {
|
||||
$struct->next_reinforce_apply = $structure->next_reinforce_apply;
|
||||
}
|
||||
if(isset($structure->next_reinforce_hour)) {
|
||||
$struct->next_reinforce_hour = $structure->next_reinforce_hour;
|
||||
}
|
||||
if(isset($structure->next_reinforce_weekday)) {
|
||||
$struct->next_reinforce_weekday = $structure->next_reinforce_weekday;
|
||||
}
|
||||
$struct->reinforce_hour = $structure->reinforce_hour;
|
||||
if(isset($structure->reinforce_weekday)) {
|
||||
$struct->reinforce_weekday = $structure->reinforce_weekday;
|
||||
}
|
||||
if(isset($structure->unanchors_at)) {
|
||||
$struct->unanchors_at = $structure->unanchors_at;
|
||||
}
|
||||
//If we set the structure services to true, let's save the services
|
||||
if($structure->services == true) {
|
||||
$this->StorestructureServices($structure->services, $structure->structure_id);
|
||||
}
|
||||
|
||||
$this->structureInfo = $structure;
|
||||
//Save the database record
|
||||
$struct->save();
|
||||
}
|
||||
|
||||
public function UpdateExistingStructure($structure, $info, $solarName) {
|
||||
//For each line see if it is part of the structure array, and attempt to modify each variable
|
||||
//This will be implemented in the near future.
|
||||
|
||||
if(isset($structure->services)) {
|
||||
foreach($structure->services as $service) {
|
||||
//Search for the service, and if found, update it, else add it.
|
||||
$serviceFound = Service::where([
|
||||
'structure_id' => $structure->structure_id,
|
||||
'name' => $service->name,
|
||||
])->get();
|
||||
if($serviceFound) {
|
||||
Service::where([
|
||||
'structure_id' => $structure->structure_id,
|
||||
'name' => $service->name,
|
||||
])->update([
|
||||
'state' => $service->state,
|
||||
]);
|
||||
} else {
|
||||
$newService = new Service;
|
||||
$newService->structure_id = $structure->structure_id;
|
||||
$newService->name = $service->name;
|
||||
$newService->state = $service->state;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public 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();
|
||||
|
||||
$dateTime = $esiHelper->DecodeDate($date);
|
||||
|
||||
return $dateTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ class Asset extends Model
|
||||
//Timestamps
|
||||
public $timestamps = true;
|
||||
|
||||
//Primary Key
|
||||
public $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable
|
||||
*
|
||||
|
||||
@@ -12,6 +12,9 @@ class Service extends Model
|
||||
//Timestamps
|
||||
public $timestamps = false;
|
||||
|
||||
//Primary Key
|
||||
public $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable
|
||||
*
|
||||
|
||||
@@ -14,6 +14,9 @@ class Structure extends Model
|
||||
//Table Name
|
||||
public $table = 'alliance_structures';
|
||||
|
||||
//Primary Key
|
||||
public $primaryKey = 'structure_id';
|
||||
|
||||
//Timestamps
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@ class CorporationAssetsTable extends Migration
|
||||
{
|
||||
if(!Schema::hasTable('alliance_structures')) {
|
||||
Schema::create('alliance_structures', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('structure_id');
|
||||
$table->string('structure_id')->primary()->unique();
|
||||
$table->string('structure_name');
|
||||
$table->string('solar_system_id');
|
||||
$table->string('solar_system_name')->nullable();
|
||||
@@ -42,7 +41,7 @@ class CorporationAssetsTable extends Migration
|
||||
|
||||
if(!Schema::hasTable('structure_services')) {
|
||||
Schema::create('structure_services', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->increments('id')->primary();
|
||||
$table->string('structure_id');
|
||||
$table->string('name');
|
||||
$table->string('state');
|
||||
@@ -51,7 +50,7 @@ class CorporationAssetsTable extends Migration
|
||||
|
||||
if(!Schema::hasTable('alliance_assets')) {
|
||||
Schema::create('alliance_assets', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->increments('id')->primary();
|
||||
$table->boolean('is_blueprint_copy')->nullable();
|
||||
$table->boolean('is_singleton');
|
||||
$table->string('item_id');
|
||||
|
||||
Reference in New Issue
Block a user