Check permissions and show error if the database setup fails
This commit is contained in:
parent
b227090f54
commit
9607c0a27f
@ -1,14 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'php' => [
|
'php' => [
|
||||||
'version' => '7.0.0'
|
'version' => '7.0.0'
|
||||||
],
|
],
|
||||||
|
|
||||||
# TODO: Remove eventually
|
|
||||||
// 'env_postfix' => '.generated',
|
|
||||||
'env_postfix' => '',
|
'env_postfix' => '',
|
||||||
|
|
||||||
'extensions' => [
|
'extensions' => [
|
||||||
@ -20,9 +16,15 @@ return [
|
|||||||
'cURL',
|
'cURL',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
# Make sure these are writable
|
||||||
'permissions' => [
|
'permissions' => [
|
||||||
'storage/framework/' => 'writeable',
|
'bootstrap/cache',
|
||||||
'storage/logs/' => 'writeable',
|
'storage',
|
||||||
'bootstrap/cache/' => 'writable'
|
'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;
|
namespace Modules\Installer\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
use Log;
|
use Log;
|
||||||
use Illuminate\Http\Request;
|
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
|
* Step 1. Check the modules and permissions
|
||||||
*/
|
*/
|
||||||
public function step1(Request $request)
|
public function step1(Request $request)
|
||||||
{
|
{
|
||||||
$passed = true;
|
|
||||||
$php_version = $this->reqService->checkPHPVersion();
|
$php_version = $this->reqService->checkPHPVersion();
|
||||||
if($php_version['passed'] === false) {
|
|
||||||
$passed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$extensions = $this->reqService->checkExtensions();
|
$extensions = $this->reqService->checkExtensions();
|
||||||
foreach ($extensions as $ext) {
|
$directories = $this->reqService->checkPermissions();
|
||||||
if($ext['passed'] === false) {
|
|
||||||
$passed = false;
|
# 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', [
|
return view('installer::steps/step1-requirements', [
|
||||||
'php' => $php_version,
|
'php' => $php_version,
|
||||||
'extensions' => $extensions,
|
'extensions' => $extensions,
|
||||||
|
'directories' => $directories,
|
||||||
'passed' => $passed,
|
'passed' => $passed,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -123,16 +142,16 @@ class InstallerController extends AppBaseController
|
|||||||
*/
|
*/
|
||||||
public function dbsetup(Request $request)
|
public function dbsetup(Request $request)
|
||||||
{
|
{
|
||||||
$log = [];
|
try {
|
||||||
|
$console_out = $this->dbService->setupDB($request->input('db_conn'));
|
||||||
$log[] = 'Creating database';
|
} catch(QueryException $e) {
|
||||||
$console_out = $this->dbService->setupDB($request->input('db_conn'));
|
flash()->error($e->getMessage());
|
||||||
|
return redirect(route('installer.step2'));
|
||||||
|
}
|
||||||
|
|
||||||
return view('installer::steps/step2a-completed', [
|
return view('installer::steps/step2a-completed', [
|
||||||
'console_output' => $console_out
|
'console_output' => $console_out
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//return redirect('/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
<link rel="stylesheet"
|
<link rel="stylesheet"
|
||||||
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
|
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')
|
@yield('css')
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -44,18 +47,18 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="justify-content-center" id="navigation" style="margin-left: 50px; color: white; font-size: 20px;">
|
<div class="justify-content-center" id="navigation" style="margin-left: 50px; color: white; font-size: 20px;">
|
||||||
@yield('title')
|
@yield('title')
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<!-- End Navbar -->
|
<!-- End Navbar -->
|
||||||
<div class="clearfix" style="height: 25px;"></div>
|
{{--<div class="clearfix" style="height: 25px;"></div>--}}
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
<div class="container" style="width: 50%">
|
<div class="container" style="width: 50%">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
@include('flash::message')
|
@include('installer::flash.message')
|
||||||
@yield('content')
|
@yield('content')
|
||||||
</div>
|
</div>
|
||||||
</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="container">
|
||||||
<div class="alert-icon">
|
<div class="alert-icon">
|
||||||
<i class="now-ui-icons ui-2_like"></i>
|
<i class="now-ui-icons ui-2_like"></i>
|
||||||
</div>
|
</div>
|
||||||
{!! $message !!}
|
{!! $message['message'] !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
|
{{ session()->forget('flash_notification') }}
|
||||||
|
@ -29,6 +29,20 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@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>
|
</table>
|
||||||
@if($passed === true)
|
@if($passed === true)
|
||||||
<p style="text-align: right">
|
<p style="text-align: right">
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
{!! Form::open(['route' => 'installer.envsetup', 'method' => 'POST']) !!}
|
{!! Form::open(['route' => 'installer.envsetup', 'method' => 'POST']) !!}
|
||||||
<table class="table" width="25%">
|
<table class="table" width="25%">
|
||||||
<tr>
|
<tr>
|
||||||
<td>Select Database Type</td>
|
<td><p>Select Database Type</p></td>
|
||||||
<td style="text-align:center;">
|
<td style="text-align:center;">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{!! Form::select('db_conn', $db_types, null, ['class' => 'form-control', 'id' => 'db_conn']) !!}
|
{!! Form::select('db_conn', $db_types, null, ['class' => 'form-control', 'id' => 'db_conn']) !!}
|
||||||
|
@ -40,4 +40,34 @@ class RequirementsService {
|
|||||||
|
|
||||||
return $extensions;
|
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