App\Http\Controllers\AppController::updateSetup PHP Method

updateSetup() public method

public updateSetup ( )
    public function updateSetup()
    {
        if (Utils::isNinjaProd()) {
            return Redirect::to('/');
        }
        if (!Auth::check() && Utils::isDatabaseSetup() && Account::count() > 0) {
            return Redirect::to('/');
        }
        if (!($canUpdateEnv = @fopen(base_path() . '/.env', 'w'))) {
            Session::flash('error', 'Warning: Permission denied to write to .env config file, try running <code>sudo chown www-data:www-data /path/to/ninja/.env</code>');
            return Redirect::to('/settings/system_settings');
        }
        $app = Input::get('app');
        $db = Input::get('database');
        $mail = Input::get('mail');
        $_ENV['APP_URL'] = $app['url'];
        $_ENV['APP_DEBUG'] = Input::get('debug') ? 'true' : 'false';
        $_ENV['DB_TYPE'] = 'mysql';
        // $db['default'];
        $_ENV['DB_HOST'] = $db['type']['host'];
        $_ENV['DB_DATABASE'] = $db['type']['database'];
        $_ENV['DB_USERNAME'] = $db['type']['username'];
        $_ENV['DB_PASSWORD'] = $db['type']['password'];
        if ($mail) {
            $_ENV['MAIL_DRIVER'] = $mail['driver'];
            $_ENV['MAIL_PORT'] = $mail['port'];
            $_ENV['MAIL_ENCRYPTION'] = $mail['encryption'];
            $_ENV['MAIL_HOST'] = $mail['host'];
            $_ENV['MAIL_USERNAME'] = $mail['username'];
            $_ENV['MAIL_FROM_NAME'] = $mail['from']['name'];
            $_ENV['MAIL_PASSWORD'] = $mail['password'];
            $_ENV['MAIL_FROM_ADDRESS'] = $mail['username'];
            $_ENV['MAILGUN_DOMAIN'] = $mail['mailgun_domain'];
            $_ENV['MAILGUN_SECRET'] = $mail['mailgun_secret'];
        }
        $config = '';
        foreach ($_ENV as $key => $val) {
            if (is_array($val)) {
                continue;
            }
            if (preg_match('/\\s/', $val)) {
                $val = "'{$val}'";
            }
            $config .= "{$key}={$val}\n";
        }
        $fp = fopen(base_path() . '/.env', 'w');
        fwrite($fp, $config);
        fclose($fp);
        Session::flash('message', trans('texts.updated_settings'));
        return Redirect::to('/settings/system_settings');
    }