Check permissions and show error if the database setup fails
This commit is contained in:
parent
b227090f54
commit
9607c0a27f
@ -1,14 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
return [
|
||||
'php' => [
|
||||
'version' => '7.0.0'
|
||||
],
|
||||
|
||||
# TODO: Remove eventually
|
||||
// 'env_postfix' => '.generated',
|
||||
'env_postfix' => '',
|
||||
|
||||
'extensions' => [
|
||||
@ -20,9 +16,15 @@ return [
|
||||
'cURL',
|
||||
],
|
||||
|
||||
# Make sure these are writable
|
||||
'permissions' => [
|
||||
'storage/framework/' => 'writeable',
|
||||
'storage/logs/' => 'writeable',
|
||||
'bootstrap/cache/' => 'writable'
|
||||
'bootstrap/cache',
|
||||
'storage',
|
||||
'storage/app/public',
|
||||
'storage/framework',
|
||||
'storage/framework/cache',
|
||||
'storage/framework/sessions',
|
||||
'storage/framework/views',
|
||||
'storage/logs',
|
||||
],
|
||||
];
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Installer\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Log;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@ -61,27 +62,45 @@ class InstallerController extends AppBaseController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any of the items has been marked as failed
|
||||
* @param array $arr
|
||||
* @return bool
|
||||
*/
|
||||
protected function allPassed(array $arr): bool
|
||||
{
|
||||
foreach($arr as $item) {
|
||||
if($item['passed'] === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 1. Check the modules and permissions
|
||||
*/
|
||||
public function step1(Request $request)
|
||||
{
|
||||
$passed = true;
|
||||
$php_version = $this->reqService->checkPHPVersion();
|
||||
if($php_version['passed'] === false) {
|
||||
$passed = false;
|
||||
}
|
||||
|
||||
$extensions = $this->reqService->checkExtensions();
|
||||
foreach ($extensions as $ext) {
|
||||
if($ext['passed'] === false) {
|
||||
$passed = false;
|
||||
}
|
||||
}
|
||||
$directories = $this->reqService->checkPermissions();
|
||||
|
||||
# Only pass if all the items in the ext and dirs are passed
|
||||
$statuses = [
|
||||
$php_version['passed'] === true,
|
||||
$this->allPassed($extensions) === true,
|
||||
$this->allPassed($directories) === true
|
||||
];
|
||||
|
||||
# Make sure there are no false values
|
||||
$passed = ! in_array(false, $statuses, true);
|
||||
|
||||
return view('installer::steps/step1-requirements', [
|
||||
'php' => $php_version,
|
||||
'extensions' => $extensions,
|
||||
'directories' => $directories,
|
||||
'passed' => $passed,
|
||||
]);
|
||||
}
|
||||
@ -123,16 +142,16 @@ class InstallerController extends AppBaseController
|
||||
*/
|
||||
public function dbsetup(Request $request)
|
||||
{
|
||||
$log = [];
|
||||
|
||||
$log[] = 'Creating database';
|
||||
$console_out = $this->dbService->setupDB($request->input('db_conn'));
|
||||
try {
|
||||
$console_out = $this->dbService->setupDB($request->input('db_conn'));
|
||||
} catch(QueryException $e) {
|
||||
flash()->error($e->getMessage());
|
||||
return redirect(route('installer.step2'));
|
||||
}
|
||||
|
||||
return view('installer::steps/step2a-completed', [
|
||||
'console_output' => $console_out
|
||||
]);
|
||||
|
||||
//return redirect('/');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,9 @@
|
||||
<link rel="stylesheet"
|
||||
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
|
||||
|
||||
<style>
|
||||
.table tr:first-child td { border-top: 0px; }
|
||||
</style>
|
||||
@yield('css')
|
||||
</head>
|
||||
|
||||
@ -44,18 +47,18 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="justify-content-center" id="navigation" style="margin-left: 50px; color: white; font-size: 20px;">
|
||||
@yield('title')
|
||||
@yield('title')
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<!-- End Navbar -->
|
||||
<div class="clearfix" style="height: 25px;"></div>
|
||||
{{--<div class="clearfix" style="height: 25px;"></div>--}}
|
||||
<div class="wrapper">
|
||||
<div class="clear"></div>
|
||||
<div class="container" style="width: 50%">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('flash::message')
|
||||
@include('installer::flash.message')
|
||||
@yield('content')
|
||||
</div>
|
||||
</div>
|
||||
|
8
modules/Installer/Resources/views/flash/dbtest.blade.php
Normal file
8
modules/Installer/Resources/views/flash/dbtest.blade.php
Normal file
@ -0,0 +1,8 @@
|
||||
<div class="alert alert-{!! $status !!}" role="alert">
|
||||
<div class="container">
|
||||
<div class="alert-icon">
|
||||
<i class="now-ui-icons ui-1_bell-53"></i>
|
||||
</div>
|
||||
{!! $message !!}
|
||||
</div>
|
||||
</div>
|
@ -1,8 +1,11 @@
|
||||
<div class="alert alert-{!! $status !!}" role="alert">
|
||||
@foreach (session('flash_notification', collect())->toArray() as $message)
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<div class="container">
|
||||
<div class="alert-icon">
|
||||
<i class="now-ui-icons ui-2_like"></i>
|
||||
</div>
|
||||
{!! $message !!}
|
||||
{!! $message['message'] !!}
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
{{ session()->forget('flash_notification') }}
|
||||
|
@ -29,6 +29,20 @@
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
<tr><td colspan="2"><h4>directory permissions</h4></td></tr>
|
||||
@foreach($directories as $dir)
|
||||
<tr>
|
||||
<td>{!! $dir['dir'] !!}</td>
|
||||
<td style="text-align:center;">
|
||||
@if($dir['passed'] === true)
|
||||
<span class="badge badge-success">OK!</span>
|
||||
@else
|
||||
<span class="badge badge-danger">Failed!</span>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
@if($passed === true)
|
||||
<p style="text-align: right">
|
||||
|
@ -5,7 +5,7 @@
|
||||
{!! Form::open(['route' => 'installer.envsetup', 'method' => 'POST']) !!}
|
||||
<table class="table" width="25%">
|
||||
<tr>
|
||||
<td>Select Database Type</td>
|
||||
<td><p>Select Database Type</p></td>
|
||||
<td style="text-align:center;">
|
||||
<div class="form-group">
|
||||
{!! Form::select('db_conn', $db_types, null, ['class' => 'form-control', 'id' => 'db_conn']) !!}
|
||||
|
@ -40,4 +40,34 @@ class RequirementsService {
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the permissions for the directories specified
|
||||
* Make sure they exist and are writable
|
||||
* @return array
|
||||
*/
|
||||
public function checkPermissions(): array
|
||||
{
|
||||
$directories = [];
|
||||
foreach (config('installer.permissions') as $dir)
|
||||
{
|
||||
$pass = true;
|
||||
$path = base_path($dir);
|
||||
|
||||
if(!file_exists($path)) {
|
||||
$pass = false;
|
||||
}
|
||||
|
||||
if(!is_writable($path)) {
|
||||
$pass = false;
|
||||
}
|
||||
|
||||
$directories[] = [
|
||||
'dir' => $dir,
|
||||
'passed' => $pass,
|
||||
];
|
||||
}
|
||||
|
||||
return $directories;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user