Some more updates to the installer and env file stuff

This commit is contained in:
Nabeel Shahzad
2018-01-18 21:40:25 -05:00
parent 467a1a1dc6
commit a54ff2643f
6 changed files with 42 additions and 132 deletions

View File

@@ -2,15 +2,14 @@
namespace Modules\Installer\Http\Controllers;
use Irazasyed\LaravelGAMP\Facades\GAMP;
use Log;
use Irazasyed\LaravelGAMP\Facades\GAMP;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Validator;
use App\Models\User;
use App\Models\Setting;
use App\Repositories\AirlineRepository;
use App\Facades\Utils;
use App\Services\UserService;
@@ -53,11 +52,6 @@ class InstallerController extends Controller
return view('installer::errors/already-installed');
}
/*$gamp = GAMP::setClientId(uniqid('', true));
$gamp->setDocumentPath('/install');
$gamp->setCustomDimension(PHP_VERSION, 1);
$gamp->sendPageview();*/
return view('installer::index-start');
}
@@ -127,7 +121,7 @@ class InstallerController extends Controller
];
# Make sure there are no false values
$passed = ! in_array(false, $statuses, true);
$passed = !\in_array(false, $statuses, true);
return view('installer::steps/step1-requirements', [
'php' => $php_version,
@@ -150,6 +144,8 @@ class InstallerController extends Controller
/**
* Step 2a. Create the .env
* @param Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function envsetup(Request $request)
{
@@ -186,6 +182,8 @@ class InstallerController extends Controller
/**
* Step 2b. Setup the database
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
*/
public function dbsetup(Request $request)
{
@@ -210,10 +208,6 @@ class InstallerController extends Controller
*/
public function step3(Request $request)
{
/*$this->envService->updateKeyInFile([
'APP_ENABLE_ANALYTICS' => 'false'
]);*/
return view('installer::steps/step3-user', []);
}
@@ -221,6 +215,7 @@ class InstallerController extends Controller
* Step 3 submit
* @param Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws \RuntimeException
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function usersetup(Request $request)
@@ -273,6 +268,18 @@ class InstallerController extends Controller
# Set the intial admin e-mail address
setting('general.admin_email', $user->email);
$gamp = GAMP::setClientId(uniqid('', true));
$gamp->setDocumentPath('/install');
$gamp->setCustomDimension(PHP_VERSION, 1);
$gamp->sendPageview();
# If analytics are disabled
if((int) $request->post('analytics') === 0) {
$this->envService->updateKeysInEnv([
'APP_ANALYTICS_DISABLED' => 'true',
]);
}
return view('installer::steps/step3a-completed', []);
}

View File

@@ -80,11 +80,11 @@
<td><p>Analytics</p></td>
<td>
<div class="form-group">
{!! Form::hidden('hidden', 0) !!}
{!! Form::hidden('analytics', 0) !!}
{!! Form::checkbox('analytics', 1, true, ['class' => 'form-control']) !!}
<br />
<p>
Allow collection of analytics. They're anonymized, and helps us track
Allows collection of analytics. They won't identify you, and helps us to track
the PHP and database versions that are used, and help to figure out problems
and slowdowns when vaCentral integration is enabled.
</p>

View File

@@ -9,6 +9,7 @@ APP_SKIN=default
APP_KEY=base64:{!! $APP_KEY !!}
APP_DEBUG=true
APP_LOCALE=en
APP_ANALYTICS_DISABLED=false
PHPVMS_INSTALLED=true
PHPVMS_VA_NAME="phpvms"
@@ -19,8 +20,6 @@ APP_LOG=daily
APP_LOG_LEVEL=debug
APP_LOG_MAX_FILES=3
APP_ENABLE_ANALYTICS=true
DB_CONNECTION={!! $DB_CONN !!}
DB_HOST={!! $DB_HOST !!}
DB_PORT={!! $DB_PORT !!}

View File

@@ -15,10 +15,16 @@ class EnvironmentService
{
/**
* Create the .env file
* @param $driver
* @param $host
* @param $port
* @param $name
* @param $user
* @param $pass
* @return boolean
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
*/
public function createEnvFile($driver, $host, $port, $name, $user, $pass)
public function createEnvFile($driver, $host, $port, $name, $user, $pass): bool
{
$opts = [
'APP_ENV' => 'dev',
@@ -53,11 +59,20 @@ class EnvironmentService
$env_file = file_get_contents($app->environmentFilePath());
foreach($kvp as $key => $value) {
# cast
$key = strtoupper($key);
# cast for any boolean values
if(\is_bool($value)) {
$value = $value === true ? 'true' : 'false';
}
# surround by quotes if there are any spaces in the value
if(strpos($value, ' ') !== false) {
$value = '"'.$value.'"';
}
Log::info('Replacing "' . $key . '" with ' . $value);
$env_file = preg_replace(
'/^' . $key . '(.*)?/m',
$key . '=' . $value,
@@ -72,7 +87,7 @@ class EnvironmentService
* Generate a fresh new APP_KEY
* @return string
*/
protected function createAppKey()
protected function createAppKey(): string
{
return base64_encode(Encrypter::generateKey(config('app.cipher')));
}
@@ -142,30 +157,6 @@ class EnvironmentService
return $opts;
}
/**
* Update a key/value pair in the env file
* @param $key
* @param $value
*/
public static function changeEnvironmentVariable($key, $value, $quoted=false)
{
$env_file = \App::environmentFilePath();
if (\is_bool(env($key))) {
$old = env($key) ? 'true' : 'false';
}
if($quoted) {
$value = '"'.$value.'"';
}
if (file_exists($env_file)) {
file_put_contents($env_file, str_replace(
"$key=" . $old, "$key=" . $value, file_get_contents($env_file)
));
}
}
/**
* Get the template file name and write it out
* @param $opts