structure jobs
This commit is contained in:
114
app/Console/Commands/GetStructures.php
Normal file
114
app/Console/Commands/GetStructures.php
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use DB;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//Job
|
||||||
|
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use Seat\Eseye\Cache\NullCache;
|
||||||
|
use Seat\Eseye\Configuration;
|
||||||
|
use Seat\Eseye\Containers\EsiAuthentication;
|
||||||
|
use Seat\Eseye\Eseye;
|
||||||
|
|
||||||
|
class GetStructures extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'command:GetStructures';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Get the list of structures ';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
|
||||||
|
//ESI Scope Check
|
||||||
|
$esiHelper = new Esi();
|
||||||
|
$structureScope = $esiHelper->HaveEsiScope($charId, 'esi-universe.read_structures.v1');
|
||||||
|
$corpStructureScope = $esiHelper->HaveEsiScope($charId, 'esi-corporations.read_structures.v1');
|
||||||
|
|
||||||
|
if($structureScope == false || $corpStructureScope == false) {
|
||||||
|
Log::critical("Scope check for esi failed.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Setup the esi authentication container
|
||||||
|
$config = config('esi');
|
||||||
|
//Get the refresh token from the database
|
||||||
|
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
|
||||||
|
$authentication = new EsiAuthentication([
|
||||||
|
'client_id' => $config['client_id'],
|
||||||
|
'secret' => $config['secret'],
|
||||||
|
'refresh_token' => $token[0]->refresh_token,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$esi = new Eseye($authentication);
|
||||||
|
|
||||||
|
//Set the current page
|
||||||
|
$currentPage = 1;
|
||||||
|
//Set our default total pages, and we will refresh this later
|
||||||
|
$totalPages = 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
$structures = $esi->page($currentPage)
|
||||||
|
->invoke('get', '/corporations/{corporation_id}/structures/', [
|
||||||
|
'corporation_id' => 98287666,
|
||||||
|
]);
|
||||||
|
} catch (RequestFailedException $e) {
|
||||||
|
Log::critical("Failed to get structure list.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set the total pages we need to cycle through
|
||||||
|
if($totalPages == 1) {
|
||||||
|
$totalPages = $structures->pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Dispatch a job to get all of the structure information from ESI
|
||||||
|
foreach($structures as $structure) {
|
||||||
|
$job = new JobProcessStructure;
|
||||||
|
$job->charId = 93738489;
|
||||||
|
$job->corpId = 98287666;
|
||||||
|
$job->structure = $structure;
|
||||||
|
JobProcessStructure::dispatch($job)->onQueue('default');
|
||||||
|
}
|
||||||
|
|
||||||
|
} while ($currentPage < $totalPages);
|
||||||
|
|
||||||
|
//Mark the job as finished
|
||||||
|
$task->SetStopStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
43
app/Jobs/ProcessStructureJob.php
Normal file
43
app/Jobs/ProcessStructureJob.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//App Library
|
||||||
|
use App\Library\Structures\StructureHelper;
|
||||||
|
use App\Jobs\Library\JobHelper;
|
||||||
|
|
||||||
|
//App Models
|
||||||
|
use App\Models\Jobs\JobProcessStructure;
|
||||||
|
use App\Models\Job\JobStatus;
|
||||||
|
|
||||||
|
class ProcessStructureJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,6 @@ use App\Jobs\Library\JobHelper;
|
|||||||
|
|
||||||
//App Models
|
//App Models
|
||||||
use App\Models\Jobs\JobProcessWalletTransaction;
|
use App\Models\Jobs\JobProcessWalletTransaction;
|
||||||
use App\Models\Jobs\JobError;
|
|
||||||
use App\Models\Jobs\JobStatus;
|
use App\Models\Jobs\JobStatus;
|
||||||
|
|
||||||
class ProcessWalletTransactionJob implements ShouldQueue
|
class ProcessWalletTransactionJob implements ShouldQueue
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ use Seat\Eseye\Exceptions\RequestFailedException;
|
|||||||
use App\Models\Esi\EsiScope;
|
use App\Models\Esi\EsiScope;
|
||||||
use App\Models\Esi\EsiToken;
|
use App\Models\Esi\EsiToken;
|
||||||
use App\Models\Mail\EveMail;
|
use App\Models\Mail\EveMail;
|
||||||
use App\Models\Jobs\JobError;
|
|
||||||
use App\Models\Jobs\JobStatus;
|
use App\Models\Jobs\JobStatus;
|
||||||
|
|
||||||
class SendEveMailJob implements ShouldQueue
|
class SendEveMailJob implements ShouldQueue
|
||||||
|
|||||||
90
app/Library/Stock/StockHelper.php
Normal file
90
app/Library/Stock/StockHelper.php
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* W4RP Services
|
||||||
|
* GNU Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Library\Structures\Helper;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use DB;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//Job
|
||||||
|
use App\Jobs\ProcessStocksJob;
|
||||||
|
|
||||||
|
//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;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$esi = new Esi();
|
||||||
|
|
||||||
|
$assetScope = $esi->HaveEsiScope($charId, 'esi-assets.read_corporation_assets.v1');
|
||||||
|
|
||||||
|
if($assetScope == false) {
|
||||||
|
$scopeCheck = false;
|
||||||
|
} else {
|
||||||
|
$scopeCheck = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetAssetList() {
|
||||||
|
if($this->scopeCheck == false) {
|
||||||
|
Log::critical("Structure Stock Helper didn't have the correct scopes available.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Setup the esi authentication container
|
||||||
|
$config = config('esi');
|
||||||
|
$authentication = new EsiAuthentication([
|
||||||
|
'client_id'=> $config['client_id'],
|
||||||
|
'secret' => $config['secret'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$esi = new Eseye($authentication);
|
||||||
|
try {
|
||||||
|
$newAssets = $esi->invoke('get', '/corporations/{corporation_id}/assets/', [
|
||||||
|
'corporation_id' => 98287666,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
Log::critical($e->getEsiExceptionResponse());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//How to deal with stale data in this table?
|
||||||
|
|
||||||
|
foreach($newAssets as $asset) {
|
||||||
|
//See if the asset is in the asset table already.
|
||||||
|
$found = Asset::where(['item_id' => $asset['item_id']]);
|
||||||
|
if(!$found) {
|
||||||
|
$newItem = new Asset;
|
||||||
|
if(isset($asset['is_blueprint_copy'])) {
|
||||||
|
$newItem->is_blueprint_coopy = $asset['is_blueprint_copy'];
|
||||||
|
}
|
||||||
|
$newItem->is_singleton = $asset['is_singleton'];
|
||||||
|
$newItem->item_id = $asset['item_id'];
|
||||||
|
$newItem->location_flag = $asset['location_flag'];
|
||||||
|
$newItem->location_id = $asset['location_id'];
|
||||||
|
$newItem->location_type = $asset['location_type'];
|
||||||
|
$newItem->quantity = $asset['quantity'];
|
||||||
|
$newItem->type_id = $asset['type_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -5,12 +5,13 @@
|
|||||||
* GNU Public License
|
* GNU Public License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Library\Stock\Helper;
|
namespace App\Library\Structures\Helper;
|
||||||
|
|
||||||
//Internal Library
|
//Internal Library
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use DB;
|
use DB;
|
||||||
|
use Log;
|
||||||
|
|
||||||
//Job
|
//Job
|
||||||
use App\Jobs\ProcessStocksJob;
|
use App\Jobs\ProcessStocksJob;
|
||||||
@@ -29,26 +30,21 @@ class StructureStockHelper {
|
|||||||
|
|
||||||
private $scopeCheck;
|
private $scopeCheck;
|
||||||
|
|
||||||
public function __construct() {
|
private $structureInfo;
|
||||||
$esi = new Esi();
|
|
||||||
|
|
||||||
$assetScope = $esi->HaveEsiScope($charId, 'esi-assets.read_corporation_assets.v1');
|
public function __construct($structure) {
|
||||||
|
$esi = new Esi();
|
||||||
$structureScope = $esi->HaveEsiScope($charId, 'esi-universe.read_structurs.v1');
|
$structureScope = $esi->HaveEsiScope($charId, 'esi-universe.read_structurs.v1');
|
||||||
|
|
||||||
if($assetScope == false || $structureScope == false) {
|
if($structureScope == false) {
|
||||||
$scopeCheck = false;
|
$this->scopeCheck = false;
|
||||||
} else {
|
} else {
|
||||||
$scopeCheck = true;
|
$this->scopeCheck = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetStructures() {
|
$this->structureInfo = $structure;
|
||||||
if($this->scopeCheck == false) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
25
app/Models/Jobs/JobProcessStructure.php
Normal file
25
app/Models/Jobs/JobProcessStructure.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class JobProcessStructure extends Model
|
||||||
|
{
|
||||||
|
//Table Name - Not Needed for a Job
|
||||||
|
//public $table = null;
|
||||||
|
|
||||||
|
//Timestamps
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'charId',
|
||||||
|
'corporationId',
|
||||||
|
'structure',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ class Asset extends Model
|
|||||||
public $table = 'alliance_asset';
|
public $table = 'alliance_asset';
|
||||||
|
|
||||||
//Timestamps
|
//Timestamps
|
||||||
public $timestamps = false;
|
public $timestamps = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable
|
* The attributes that are mass assignable
|
||||||
|
|||||||
Reference in New Issue
Block a user