/** * Execute the console command. * */ public function fire() { $this->info('Requesting all applications from Steam'); $steamApplicationInterface = $this->steamApplicationInterface->getApplicationList(); $this->info('Importing ' . count($steamApplicationInterface) . ' applications from Steam into database (this will take up to 5 minutes)'); $successCount = 0; $failureCount = 0; $applicationsCreated = 0; foreach ($steamApplicationInterface as $steamApp) { $newApp = NULL; try { // Search for the application in the database to update it if it already exists $application = Application::where('steam_app_id', $steamApp->id)->first(); if (!$application) { $application = new Application(); $newApp = true; } // Assign fields $application->steam_app_id = $steamApp->id; $application->name = $steamApp->name; // Insert new OR update existing with fields above $application->save(); $successCount++; if ($newApp) { $applicationsCreated++; } } catch (\Exception $e) { $this->error('Unable to import application ' . $steamApp->id . ' "' . $steamApp->name . '" : ' . $e->getMessage()); $failureCount++; } } $this->info($successCount . ' Steam applications successfully imported. New: ' . $applicationsCreated); if ($failureCount > 0) { $this->error($failureCount . ' Steam applications were not imported due to errors'); } }
/** * Transform resource into standard output format with correct typing * @param object BaseModel Resource being transformed * @return array Transformed object array ready for output */ public function transform(Application $application) { return ['id' => (int) $application->id, 'name' => $application->name, 'steam_app_id' => $application->steam_app_id, 'url' => $application->present()->url, 'logo_small' => $application->present()->smallLogo, 'logo_medium' => $application->present()->mediumLogo, 'logo_large' => $application->present()->largeLogo, 'links' => [['rel' => 'self', 'uri' => url() . '/applications/' . $application->id]]]; }
/** * Execute the console command. * */ public function fire() { $users = User::where('visible', 1)->get()->lists('steam_id_64'); if (count($users) == 0) { $this->info('No users in database'); return; } $this->info('Requesting current status of ' . count($users) . ' users from Steam'); $steamUserInterface = $this->steamUserInterface->getUsers($users); if (count($steamUserInterface) < count($users)) { $this->error('Steam responded with ' . (count($users) - count($steamUserInterface)) . ' fewer users than requested'); } $successCount = 0; $failureCount = 0; $missingApps = []; foreach ($steamUserInterface as $steamUser) { $currentApplication = NULL; $currentServer = NULL; try { // Find the user to which the state belongs to $user = User::where('steam_id_64', $steamUser->id)->first(); // Update user details with steam details if they have changed if ($user->username != $steamUser->username) { $user->username = $steamUser->username; } if ($user->avatar != $steamUser->avatar_url) { $user->avatar = $steamUser->avatar_url; } if ($user->steam_visibility != $steamUser->visibility) { $user->steam_visibility = $steamUser->visibility; } $user->save(); // If the user is currently running an app if (is_numeric($steamUser->current_app_id)) { // Find database application ID $currentApplication = Application::where('steam_app_id', $steamUser->current_app_id)->first(); if (!count($currentApplication)) { $missingApps[] = $steamUser->current_app_id; $currentApplication = NULL; } } // If the user is currently running an app and connected to a server if ($currentApplication && isset($steamUser->current_server_ip)) { // Find database server ID $currentServer = Server::where('address', $steamUser->current_server_ip)->where('port', $steamUser->current_server_port)->first(); // Create server if it does not already exist if (!count($currentServer)) { $currentServer = new Server(); $currentServer->application_id = $currentApplication->id; $currentServer->address = $steamUser->current_server_ip; $currentServer->port = $steamUser->current_server_port; $currentServer->save(); } } // Create a new state $state = new State(); $state->user_id = $user->id; $state->status = $steamUser->status; if ($currentApplication) { $state->application_id = $currentApplication->id; } if ($currentServer) { $state->server_id = $currentServer->id; } $state->save(); $successCount++; // Only incremented if no exceptions above } catch (\Exception $e) { $this->error('Unable to insert user state for user [' . $steamUser->id . ']: ' . $e->getMessage()); $failureCount++; } } // Provide info on results if ($successCount > 0) { $this->info($successCount . ' Steam user states successfully imported'); } if (count($missingApps) > 0) { $this->error(count($missingApps) . ' ' . str_plural('application', count($missingApps)) . ' missing from local database - Please run "steam:import-apps"'); } }