<commit_before><?php namespace Zeropingheroes\Lanager\Commands;

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Config, DB, Artisan;
use Tsukanov\SteamLocomotive\Locomotive;

class Install extends BaseCommand {

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'lanager:install';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Install the LANager application.';

	/**
	 * The message returned after a critical error.
	 *
	 * @var string
	 */
	protected $criticalMessage = 'Raise an issue on GitHub';

	/**
	 * Create a new command instance.
	 *
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function fire()
	{
		if( Config::get('lanager/config.installed') )
		{
			if (!$this->confirm('Installation already marked as completed - are you sure you want to continue? [yes|no]')) exit();
		}

		$this->checkRequirements();
		$this->runInstaller();
	}

	/**
	 * Check installation prerequisites are met before running installer.
	 *
	 * @return void
	 */
	private function checkRequirements()
	{
		$this->customInfo('Testing requirements before installation...');
		
		$this->checkRequirement('PHP version greater than 5.4', 
			version_compare( PHP_VERSION, '5.4' ) >= 0,
			'Install the latest stable version of PHP');

		$this->checkRequirement('Curl PHP module installed and enabled', 
			function_exists( 'curl_version' ),
			'Install and/or enable the Curl PHP module');

		$this->checkRequirement('Mcrypt PHP module installed and enabled', 
			function_exists( 'mcrypt_module_open' ),
			'Install and/or enable the Mcrypt PHP module');
		
		$this->checkRequirement('JSON PHP module installed and enabled', 
			function_exists( 'json_encode' ),
			'Install and/or enable the JSON PHP module');
	
		$this->checkRequirement('PHP accessible in the system\'s path variable', 
			$this->checkIfPhpInPath(),
			'Add PHP to the system\'s path variable and restart your OS');
		
		$this->checkRequirement('MySQL database accessible using the configured details', 
			$this->checkDatabaseConnection(),
			'Check that the MySQL database server is running and the details in /app/config/database.php are correct');

		$this->checkRequirement('Steam Web API key set', 
			strlen(Config::get('lanager/steam.apikey')) == 32,
			'Enter a valid Steam Web API key in /app/config/lanager/steam.php');

		$this->checkRequirement('Server able to access internet', 
			$this->checkInternetConnection(),
			'Check this server can access the internet');

		$this->checkRequirement('Steam Web API accessible with provided API key', 
			$this->checkSteamWebApiKey(),
			'Check that Steam is up on http://steamstat.us and that the API key set in /app/config/lanager/steam.php is correct');
		
		$this->customInfo('');
		$this->customInfo('All requirements passed - continuing with installation');
		$this->customInfo('');
	}

	/**
	 * Run installation steps.
	 *
	 * @return void
	 */
	private function runInstaller()
	{
		$this->customInfo('Creating database structure...');
		$migrate = Artisan::call('migrate', array('--path' => 'app/migrations'));
		if( $migrate != 0 ) $this->abort('Database structure creation failure', $this->criticalMessage);

		if( Config::get('lanager/config.installed') )
		{
			if( $this->confirm('Would you like to empty the database before inserting default data? [yes|no]') )
			{
				$this->emptyDatabase();
			}
		}
		$this->customInfo('Seeding database with example data...');
		$seed = Artisan::call('db:seed', array('--class' => 'Zeropingheroes\Lanager\Seeds\DatabaseSeeder'));
		if( $seed != 0 ) $this->abort('Database seeding failure', $this->criticalMessage);

		$this->customInfo('Publishing package assets...');
		$publish = Artisan::call('asset:publish');
		if( $publish != 0 ) $this->abort('Asset publishing failure', $this->criticalMessage);

		$this->customInfo('Importing Steam applications...');
		$import = Artisan::call('steam:import-apps');
		if( $import != 0 ) $this->abort('Steam app import error', $this->criticalMessage);

		$this->customInfo('Changing session driver to database in config file...');
		$sessionConfig = $this->editConfigFile('app/config/session.php', "'driver' => 'array'", "'driver' => 'database'");
		if( ! $sessionConfig ) $this->abort('Unable to change session driver', $this->criticalMessage);

		$this->customInfo('Setting application key...');
		$appKey = Artisan::call('key:generate');
		if( $import != 0 ) $this->abort('Unable to set application key', $this->criticalMessage);

		$this->customInfo('Marking LANager as installed in config file...');
		$lanagerConfig = $this->editConfigFile('app/config/lanager/config.php', "'installed'	=> false","'installed'	=> true");<commit_msg>Fixing application key check in installer command<commit_after><?php namespace Zeropingheroes\Lanager\Commands;

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Config, DB, Artisan;
use Tsukanov\SteamLocomotive\Locomotive;

class Install extends BaseCommand {

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'lanager:install';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Install the LANager application.';

	/**
	 * The message returned after a critical error.
	 *
	 * @var string
	 */
	protected $criticalMessage = 'Raise an issue on GitHub';

	/**
	 * Create a new command instance.
	 *
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function fire()
	{
		if( Config::get('lanager/config.installed') )
		{
			if (!$this->confirm('Installation already marked as completed - are you sure you want to continue? [yes|no]')) exit();
		}

		$this->checkRequirements();
		$this->runInstaller();
	}

	/**
	 * Check installation prerequisites are met before running installer.
	 *
	 * @return void
	 */
	private function checkRequirements()
	{
		$this->customInfo('Testing requirements before installation...');
		
		$this->checkRequirement('PHP version greater than 5.4', 
			version_compare( PHP_VERSION, '5.4' ) >= 0,
			'Install the latest stable version of PHP');

		$this->checkRequirement('Curl PHP module installed and enabled', 
			function_exists( 'curl_version' ),
			'Install and/or enable the Curl PHP module');

		$this->checkRequirement('Mcrypt PHP module installed and enabled', 
			function_exists( 'mcrypt_module_open' ),
			'Install and/or enable the Mcrypt PHP module');
		
		$this->checkRequirement('JSON PHP module installed and enabled', 
			function_exists( 'json_encode' ),
			'Install and/or enable the JSON PHP module');
	
		$this->checkRequirement('PHP accessible in the system\'s path variable', 
			$this->checkIfPhpInPath(),
			'Add PHP to the system\'s path variable and restart your OS');
		
		$this->checkRequirement('MySQL database accessible using the configured details', 
			$this->checkDatabaseConnection(),
			'Check that the MySQL database server is running and the details in /app/config/database.php are correct');

		$this->checkRequirement('Steam Web API key set', 
			strlen(Config::get('lanager/steam.apikey')) == 32,
			'Enter a valid Steam Web API key in /app/config/lanager/steam.php');

		$this->checkRequirement('Server able to access internet', 
			$this->checkInternetConnection(),
			'Check this server can access the internet');

		$this->checkRequirement('Steam Web API accessible with provided API key', 
			$this->checkSteamWebApiKey(),
			'Check that Steam is up on http://steamstat.us and that the API key set in /app/config/lanager/steam.php is correct');
		
		$this->customInfo('');
		$this->customInfo('All requirements passed - continuing with installation');
		$this->customInfo('');
	}

	/**
	 * Run installation steps.
	 *
	 * @return void
	 */
	private function runInstaller()
	{
		$this->customInfo('Creating database structure...');
		$migrate = Artisan::call('migrate', array('--path' => 'app/migrations'));
		if( $migrate != 0 ) $this->abort('Database structure creation failure', $this->criticalMessage);

		if( Config::get('lanager/config.installed') )
		{
			if( $this->confirm('Would you like to empty the database before inserting default data? [yes|no]') )
			{
				$this->emptyDatabase();
			}
		}
		$this->customInfo('Seeding database with example data...');
		$seed = Artisan::call('db:seed', array('--class' => 'Zeropingheroes\Lanager\Seeds\DatabaseSeeder'));
		if( $seed != 0 ) $this->abort('Database seeding failure', $this->criticalMessage);

		$this->customInfo('Publishing package assets...');
		$publish = Artisan::call('asset:publish');
		if( $publish != 0 ) $this->abort('Asset publishing failure', $this->criticalMessage);

		$this->customInfo('Importing Steam applications...');
		$import = Artisan::call('steam:import-apps');
		if( $import != 0 ) $this->abort('Steam app import error', $this->criticalMessage);

		$this->customInfo('Changing session driver to database in config file...');
		$sessionConfig = $this->editConfigFile('app/config/session.php', "'driver' => 'array'", "'driver' => 'database'");
		if( ! $sessionConfig ) $this->abort('Unable to change session driver', $this->criticalMessage);

		$this->customInfo('Setting application key...');
		$appKey = Artisan::call('key:generate');
		if( $appKey != 0 ) $this->abort('Unable to set application key', $this->criticalMessage);

		$this->customInfo('Marking LANager as installed in config file...');
		$lanagerConfig = $this->editConfigFile('app/config/lanager/config.php', "'installed'	=> false","'installed'	=> true");
{'fraction_non_alphanumeric': 0.15136678906568748, 'fraction_numerical': 0.0024479804161566705, 'mean_word_length': 4.337506804572673, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '83929', 'n_tokens_mistral': 3184, 'n_tokens_neox': 2848, 'n_words': 813}