diff --git a/app/Console/Commands/Moons/MoonsUpdateCommand.php b/app/Console/Commands/Moons/MoonsUpdateCommand.php index c0c550d8f..b20555708 100644 --- a/app/Console/Commands/Moons/MoonsUpdateCommand.php +++ b/app/Console/Commands/Moons/MoonsUpdateCommand.php @@ -15,8 +15,7 @@ use App\Jobs\Commands\Moons\FetchMoonObserversJob; use Commands\Library\CommandHelper; //Models -use App\Models\Moon\CorpMoonObserver; -use App\Models\Moon\CorpMoonLedger; +use App\Models\Esi\EsiScope; class MoonsUpdateCommand extends Command { @@ -51,6 +50,43 @@ class MoonsUpdateCommand extends Command */ public function handle() { - // + //Declare variables + $delay = 0; + $characters = array(); + + //Create the new command helper container + $task = new CommandHelper('MoonsUpdateCommand'); + //Set the task start status + $task->SetStartStatus(); + + //Get all of the characters who have registered structures for moon ledgers + $miningChars = EsiScope::where([ + 'scope' => 'esi-industry.read_corporation_mining.v1', + ])->get(); + + foreach($miningChars as $mChars) { + $universe = EsiScope::where([ + 'character_id' => $mChars->character_id, + 'scope' => 'esi-universe.read_structures.v1', + ])->first(); + + if($universe != null) { + array_push($characters, $universe->character_id); + } + } + + //Cycle through each of the character Ids which have the correct scopes, + //and dispatch jobs accordingly. + foreach($characters as $charId) { + //Fetch all of the corp observers with the job dispatch + FetchMoonObserverJob::dispatch($charId); + //Fetch all of the corp ledgers with the job dispatch + FetchMoonLedgerJob::dispatch($charId); + } + + + + //Set task done status + $task->SetStopStatus(); } } diff --git a/app/Http/Controllers/Moons/MoonLedgerController.php b/app/Http/Controllers/Moons/MoonLedgerController.php index 73a2bfbb2..06e1d4dff 100644 --- a/app/Http/Controllers/Moons/MoonLedgerController.php +++ b/app/Http/Controllers/Moons/MoonLedgerController.php @@ -41,7 +41,7 @@ class MoonLedgerController extends Controller $charId = auth()->user()->getId(); //Check for the esi scope to be registered already - if(!$esiHelper->HaveEsiScope($charId, 'esi-industry.read_corporation_mining.v1') || !$esiHelper->HaveEsiScope($charId, 'Need to add scope for esi-universe.read_structures.v1')) { + if(!$esiHelper->HaveEsiScope($charId, 'esi-industry.read_corporation_mining.v1') || !$esiHelper->HaveEsiScope($charId, 'esi-universe.read_structures.v1')) { return redirect('/dashboard')->with('error', 'Please register corporation mining and universe structures scopes before continuing.'); } diff --git a/app/Jobs/Commands/Moons/FetchMoonObserversJob.php b/app/Jobs/Commands/Moons/FetchMoonObserverJob.php similarity index 98% rename from app/Jobs/Commands/Moons/FetchMoonObserversJob.php rename to app/Jobs/Commands/Moons/FetchMoonObserverJob.php index 69847949f..f6569f9ee 100644 --- a/app/Jobs/Commands/Moons/FetchMoonObserversJob.php +++ b/app/Jobs/Commands/Moons/FetchMoonObserverJob.php @@ -18,7 +18,7 @@ use App\Library\Lookups\LookupHelper; //App Models use App\Models\Moon\CorpMoonObserver; -class FetchMoonObserversJob implements ShouldQueue +class FetchMoonObserverJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;