Add config.php at root; include configuration overhaul and then fixes to the installer #156
This commit is contained in:
@@ -2,25 +2,23 @@
|
||||
|
||||
namespace Modules\Installer\Http\Controllers;
|
||||
|
||||
use DB;
|
||||
use Log;
|
||||
use PDO;
|
||||
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\Enums\AnalyticsDimensions;
|
||||
|
||||
use App\Repositories\AirlineRepository;
|
||||
use App\Facades\Utils;
|
||||
use App\Services\AnalyticsService;
|
||||
use App\Services\UserService;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use Modules\Installer\Services\DatabaseService;
|
||||
use Modules\Installer\Services\EnvironmentService;
|
||||
use Modules\Installer\Services\ConfigService;
|
||||
use Modules\Installer\Services\RequirementsService;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
@@ -28,6 +26,7 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
class InstallerController extends Controller
|
||||
{
|
||||
protected $airlineRepo,
|
||||
$analyticsSvc,
|
||||
$dbService,
|
||||
$envService,
|
||||
$reqService,
|
||||
@@ -35,12 +34,14 @@ class InstallerController extends Controller
|
||||
|
||||
public function __construct(
|
||||
AirlineRepository $airlineRepo,
|
||||
AnalyticsService $analyticsSvc,
|
||||
DatabaseService $dbService,
|
||||
EnvironmentService $envService,
|
||||
ConfigService $envService,
|
||||
RequirementsService $reqService,
|
||||
UserService $userService
|
||||
) {
|
||||
$this->airlineRepo = $airlineRepo;
|
||||
$this->analyticsSvc = $analyticsSvc;
|
||||
$this->dbService = $dbService;
|
||||
$this->envService = $envService;
|
||||
$this->reqService = $reqService;
|
||||
@@ -61,12 +62,12 @@ class InstallerController extends Controller
|
||||
protected function testDb(Request $request)
|
||||
{
|
||||
$this->dbService->checkDbConnection(
|
||||
$request->input('db_conn'),
|
||||
$request->input('db_host'),
|
||||
$request->input('db_port'),
|
||||
$request->input('db_name'),
|
||||
$request->input('db_user'),
|
||||
$request->input('db_pass')
|
||||
$request->post('db_conn'),
|
||||
$request->post('db_host'),
|
||||
$request->post('db_port'),
|
||||
$request->post('db_name'),
|
||||
$request->post('db_user'),
|
||||
$request->post('db_pass')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -152,7 +153,7 @@ class InstallerController extends Controller
|
||||
*/
|
||||
public function envsetup(Request $request)
|
||||
{
|
||||
Log::info('ENV setup', $request->toArray());
|
||||
Log::info('ENV setup', $request->post());
|
||||
|
||||
// Before writing out the env file, test the DB credentials
|
||||
try {
|
||||
@@ -163,16 +164,25 @@ class InstallerController extends Controller
|
||||
}
|
||||
|
||||
// Now write out the env file
|
||||
$attrs = [
|
||||
'SITE_NAME' => $request->post('site_name'),
|
||||
'SITE_URL' => $request->post('site_url'),
|
||||
'DB_CONN' => $request->post('db_conn'),
|
||||
'DB_HOST' => $request->post('db_host'),
|
||||
'DB_PORT' => $request->post('db_port'),
|
||||
'DB_NAME' => $request->post('db_name'),
|
||||
'DB_USER' => $request->post('db_user'),
|
||||
'DB_PASS' => $request->post('db_pass'),
|
||||
'DB_PREFIX' => $request->post('db_prefix'),
|
||||
];
|
||||
|
||||
/**
|
||||
* Create the config files and then redirect so that the
|
||||
* framework can pickup all those configs, etc, before we
|
||||
* setup the database and stuff
|
||||
*/
|
||||
try {
|
||||
$this->envService->createEnvFile(
|
||||
$request->input('db_conn'),
|
||||
$request->input('db_host'),
|
||||
$request->input('db_port'),
|
||||
$request->input('db_name'),
|
||||
$request->input('db_user'),
|
||||
$request->input('db_pass')
|
||||
);
|
||||
$this->envService->createConfigFiles($attrs);
|
||||
} catch(FileException $e) {
|
||||
flash()->error($e->getMessage());
|
||||
return redirect(route('installer.step2'))->withInput();
|
||||
@@ -271,27 +281,7 @@ class InstallerController extends Controller
|
||||
# Set the intial admin e-mail address
|
||||
setting('general.admin_email', $user->email);
|
||||
|
||||
# some analytics
|
||||
$gamp = GAMP::setClientId(uniqid('', true));
|
||||
$gamp->setDocumentPath('/install');
|
||||
|
||||
$gamp->setCustomDimension(PHP_VERSION, AnalyticsDimensions::PHP_VERSION);
|
||||
|
||||
# figure out database version
|
||||
$pdo = DB::connection()->getPdo();
|
||||
$gamp->setCustomDimension(
|
||||
strtolower($pdo->getAttribute(PDO::ATTR_SERVER_VERSION)),
|
||||
AnalyticsDimensions::DATABASE_VERSION
|
||||
);
|
||||
|
||||
$gamp->sendPageview();
|
||||
|
||||
# If analytics are disabled
|
||||
if((int) $request->post('analytics') === 0) {
|
||||
$this->envService->updateKeysInEnv([
|
||||
'APP_ANALYTICS_DISABLED' => 'true',
|
||||
]);
|
||||
}
|
||||
$this->analyticsSvc->sendInstall();
|
||||
|
||||
return view('installer::steps/step3a-completed', []);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,33 @@
|
||||
<div style="align-content: center;">
|
||||
{!! Form::open(['route' => 'installer.envsetup', 'method' => 'POST']) !!}
|
||||
<table class="table" width="25%">
|
||||
|
||||
<tr>
|
||||
<td colspan="2"><h4>Site Config</h4></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Site Name</td>
|
||||
<td style="text-align:center;">
|
||||
<div class="form-group">
|
||||
{!! Form::input('text', 'site_name', 'phpvms', ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Site URL</td>
|
||||
<td style="text-align:center;">
|
||||
<div class="form-group">
|
||||
{!! Form::input('text', 'site_url', Request::root(), ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan="2"><h4>Database Config</h4></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><p>Select Database Type</p></td>
|
||||
<td style="text-align:center;">
|
||||
@@ -70,6 +97,16 @@
|
||||
|
||||
</tbody>
|
||||
|
||||
<tr>
|
||||
<td>Database Prefix</td>
|
||||
<td style="text-align:center;">
|
||||
<div class="form-group">
|
||||
{!! Form::input('text', 'db_prefix', '', ['class' => 'form-control']) !!}
|
||||
<p>Set this if you're sharing the database with another application.</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<div id="dbtest"></div>
|
||||
<p style="text-align: right">
|
||||
@@ -106,7 +143,6 @@ $(document).ready(function() {
|
||||
db_pass: $("input[name=db_pass]").val(),
|
||||
};
|
||||
|
||||
console.log(opts);
|
||||
$.post("{!! route('installer.dbtest') !!}", opts, function(data) {
|
||||
$("#dbtest").html(data);
|
||||
})
|
||||
|
||||
@@ -71,26 +71,27 @@
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{{--
|
||||
<tr>
|
||||
<td colspan="2"><h4>Options</h4></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan="2"><h4>Options</h4></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><p>Analytics</p></td>
|
||||
<td>
|
||||
<div class="form-group">
|
||||
{!! Form::hidden('analytics', 0) !!}
|
||||
{!! Form::checkbox('analytics', 1, true, ['class' => 'form-control']) !!}
|
||||
<br />
|
||||
<p>
|
||||
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>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><p>Analytics</p></td>
|
||||
<td>
|
||||
<div class="form-group">
|
||||
{!! Form::hidden('analytics', 0) !!}
|
||||
{!! Form::checkbox('analytics', 1, true, ['class' => 'form-control']) !!}
|
||||
<br />
|
||||
<p>
|
||||
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>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
--}}
|
||||
</table>
|
||||
<div id="dbtest"></div>
|
||||
<p style="text-align: right">
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
<div style="align-content: center;">
|
||||
{!! Form::open(['route' => 'installer.complete', 'method' => 'GET']) !!}
|
||||
|
||||
<h4>Install Completed!</h4>
|
||||
<h4>Installer Completed!</h4>
|
||||
|
||||
<p>Edit the <span class="code">config.php</span> to fill in some additional settings. </p>
|
||||
<p>Click the button to proceed to the login screen!</p>
|
||||
|
||||
<p style="text-align: right">
|
||||
|
||||
@@ -9,41 +9,41 @@ use Illuminate\Encryption\Encrypter;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
|
||||
/**
|
||||
* Class EnvironmentService
|
||||
* Class ConfigService
|
||||
* @package Modules\Installer\Services
|
||||
*/
|
||||
class EnvironmentService
|
||||
class ConfigService
|
||||
{
|
||||
/**
|
||||
* Create the .env file
|
||||
* @param $driver
|
||||
* @param $host
|
||||
* @param $port
|
||||
* @param $name
|
||||
* @param $user
|
||||
* @param $pass
|
||||
* @param $attrs
|
||||
* @return boolean
|
||||
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
||||
*/
|
||||
public function createEnvFile($driver, $host, $port, $name, $user, $pass): bool
|
||||
public function createConfigFiles($attrs): bool
|
||||
{
|
||||
$opts = [
|
||||
'APP_ENV' => 'dev',
|
||||
'APP_KEY' => $this->createAppKey(),
|
||||
'DB_CONN' => $driver,
|
||||
'DB_HOST' => $host,
|
||||
'DB_PORT' => $port,
|
||||
'DB_NAME' => $name,
|
||||
'DB_USER' => $user,
|
||||
'DB_PASS' => $pass,
|
||||
'SITE_NAME' => '',
|
||||
'SITE_URL' => 'http://phpvms.test',
|
||||
'DB_CONN' => '',
|
||||
'DB_HOST' => '',
|
||||
'DB_PORT' => '',
|
||||
'DB_NAME' => '',
|
||||
'DB_USER' => '',
|
||||
'DB_PASS' => '',
|
||||
'DB_PREFIX' => '',
|
||||
'DB_EMULATE_PREPARES' => false,
|
||||
];
|
||||
|
||||
$opts = array_merge($opts, $attrs);
|
||||
|
||||
$opts = $this->determinePdoOptions($opts);
|
||||
$opts = $this->getCacheDriver($opts);
|
||||
$opts = $this->getQueueDriver($opts);
|
||||
|
||||
$this->writeEnvFile($opts);
|
||||
$this->writeConfigFiles($opts);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -163,8 +163,10 @@ class EnvironmentService
|
||||
* @param $opts
|
||||
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
||||
*/
|
||||
protected function writeEnvFile($opts)
|
||||
protected function writeConfigFiles($opts)
|
||||
{
|
||||
Stub::setBasePath(resource_path('/stubs/installer'));
|
||||
|
||||
$env_file = \App::environmentFilePath();
|
||||
|
||||
if(file_exists($env_file) && !is_writable($env_file)) {
|
||||
@@ -172,27 +174,28 @@ class EnvironmentService
|
||||
throw new FileException('Can\'t write to the env.php file! Check the permissions');
|
||||
}
|
||||
|
||||
/**
|
||||
* First write out the env file
|
||||
*/
|
||||
try {
|
||||
$stub = new Stub('/env.stub', $opts);
|
||||
$stub->render();
|
||||
$stub->saveTo(\App::environmentPath(), \App::environmentFile());
|
||||
} catch(\Exception $e) {
|
||||
throw new FileException('Couldn\'t write the env.php. (' . $e . ')');
|
||||
throw new FileException('Couldn\'t write env.php. (' . $e . ')');
|
||||
}
|
||||
|
||||
/*$fp = fopen($env_file, 'wb');
|
||||
if($fp === false) {
|
||||
throw new FileException('Couldn\'t write the env.php. (' . error_get_last() .')');
|
||||
/**
|
||||
* Next write out the config file. If there's an error here,
|
||||
* then throw an exception but delete the env file first
|
||||
*/
|
||||
try {
|
||||
$stub = new Stub('/config.stub', $opts);
|
||||
$stub->render();
|
||||
$stub->saveTo(\App::environmentPath(), 'config.php');
|
||||
} catch (\Exception $e) {
|
||||
unlink(\App::environmentPath().'/'. \App::environmentFile());
|
||||
throw new FileException('Couldn\'t write config.php. (' . $e . ')');
|
||||
}
|
||||
|
||||
# render it within Blade and log the contents
|
||||
$env_contents = view('installer::stubs/env', $opts);
|
||||
Log::info($env_contents);
|
||||
|
||||
$env_contents = "<?php exit(); ?>\n\n"
|
||||
.$env_contents;
|
||||
|
||||
fwrite($fp, $env_contents);
|
||||
fclose($fp);*/
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user