SetStartStatus(); $startTime = time(); //Declare variables $config = config('esi'); $lookup = new LookupHelper; $esiHelper = new Esi; //Check for the esi scope if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) { Log::critical('Esi scopes were not found for FetchMiningTaxesObserversJob.'); print("Esi scopes not found."); return; } $char = $lookup->GetCharacterInfo($config['primary']); //Get the refresh token for the character $refreshToken = $esiHelper->GetRefreshToken($config['primary']); //Get the esi variable $esi = $esiHelper->SetupEsiAuthentication($refreshToken); try { $response = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [ 'corporation_id' => $char->corporation_id, ]); } catch(RequestFailedException $e) { Log::critical("Failed to get moon observers in FetchMiningTaxesObservers"); Log::critical($e); dd($e); } $resp = json_decode($response->raw, false); //Run through the mining observers, and add them to the database foreach($resp as $observer) { if($observer->observer_id > 1030000000000) { $found = Observer::where([ 'observer_id' => $observer->observer_id, ])->count(); if($found > 0) { Observer::where([ 'observer_id' => $observer->observer_id, ])->update([ 'observer_id' => $observer->observer_id, 'observer_type' => $observer->observer_type, 'last_updated' => $observer->last_updated, ]); } else { $newObs = new Observer; $newObs->observer_id = $observer->observer_id; $newObs->observer_type = $observer->observer_type; $newObs->last_updated = $observer->last_updated; $newObs->save(); } } } /** * Cleanup stale data that hasn't been updated in at least 1 week. */ $date = Carbon::now()->subDays(7); Observer::where('last_updated', '<', $date)->delete(); //Set the task as completed $task->SetStopStatus(); //Set the end time for debugging and printint out to the screen $endTime = time(); printf("Time to complete: " . ($endTime - $startTime) . "\n\r"); //Return 0 saying everything is fine return 0; } }