HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1') || !$esiHelper->HaveEsiScope($config['primary'], 'esi-universe.read_structures.v1')) { Log::critical('The primary character does not have the necessary scopes for FetchRentalMoonLedgerCommand.'); return; } //Get the refresh token if scope checks have passed $refreshToken = $esiHelper->GetRefreshtoken($config['primary']); //Get the character data from the lookup table if possible or esi $character = $lookup->GetCharacterInfo($config['primary']); //Get all of the rental moon observers from the database $observers = RentalMoonObserver::all(); //Dump the mining ledger table for rental moons RentalMoonLedger::truncate(); //Foreach observer get the ledger foreach($observers as $observer) { //Get the observer name. $observerInfo = Structure::where([ 'structure_id' => $observer->observer_id, ])->first(); try { $ledgers = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [ 'corporation_id' => $character->corporation_id, 'observer_id' => $observer->observer_id, ]); } catch(RequestFailedException $e) { //If an exception has occurred, then log it Log::critical('FetchRentalMoonLedger command failed to get the mining ledger for observer id: ' . $observer->observer_id); } if($ledgers != null) { foreach($ledgers as $ledger) { //Get the ore name from the lookup table $ore = $lookup->ItemIdToName($ledger->type_id); //Get the character name from the lookup helper using the characterId $charInfo = $lookup->GetCharacterInfo($ledger->character_id); //Get the corporation information $corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id); //Get the recorded corporation information $recordedCorpInfo = $lookup->GetCorporationInfo($ledger->recorded_corporation_id); $entries[] = [ 'corporation_id' => $corpInfo->corporation_id, 'corporation_name' => $corpInfo->name, 'character_id' => $ledger->character_id, 'character_name' => $charInfo->name, 'observer_id' => $observer->observer_id, 'observer_name' => $observerInfo->name, 'type_id' => $ledger->type_id, 'ore' => $ore, 'quantity' => $ledger->quantity, 'recorded_corporation_id' => $ledger->recorded_corporation_id, 'recorded_corporation_name' => $recordedCorpInfo->name, 'last_updated' => $ledger->last_updated, 'created_at' => $ledger->last_updated . ' 23:59:59', 'updated_at' => $ledger->last_updated . ' 23:59:59', ]; } //Insert or ignore each of the records saved into the array through the foreach loop RentalMoonLedger::insertOrIgnore($entries); Log::info( 'FetchRentalMoonLedgerJob inserted up to ' .count($entires) . ' new ledger entries.' ); } } } }