From 9607c0a27f2617bfc3fb602961440185589506f9 Mon Sep 17 00:00:00 2001
From: Nabeel Shahzad
Date: Fri, 15 Dec 2017 10:41:52 -0600
Subject: [PATCH] Check permissions and show error if the database setup fails
---
modules/Installer/Config/config.php | 16 +++---
.../Http/Controllers/InstallerController.php | 51 +++++++++++++------
.../Installer/Resources/views/app.blade.php | 9 ++--
.../Resources/views/flash/dbtest.blade.php | 8 +++
.../Resources/views/flash/message.blade.php | 7 ++-
.../views/steps/step1-requirements.blade.php | 14 +++++
.../Resources/views/steps/step2-db.blade.php | 2 +-
.../Services/RequirementsService.php | 30 +++++++++++
8 files changed, 108 insertions(+), 29 deletions(-)
create mode 100644 modules/Installer/Resources/views/flash/dbtest.blade.php
diff --git a/modules/Installer/Config/config.php b/modules/Installer/Config/config.php
index 44efaa95..76ea37af 100644
--- a/modules/Installer/Config/config.php
+++ b/modules/Installer/Config/config.php
@@ -1,14 +1,10 @@
[
'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',
],
];
diff --git a/modules/Installer/Http/Controllers/InstallerController.php b/modules/Installer/Http/Controllers/InstallerController.php
index 9f6c0d47..7fff0358 100644
--- a/modules/Installer/Http/Controllers/InstallerController.php
+++ b/modules/Installer/Http/Controllers/InstallerController.php
@@ -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('/');
}
/**
diff --git a/modules/Installer/Resources/views/app.blade.php b/modules/Installer/Resources/views/app.blade.php
index dfea5c51..ce188121 100644
--- a/modules/Installer/Resources/views/app.blade.php
+++ b/modules/Installer/Resources/views/app.blade.php
@@ -22,6 +22,9 @@
+
@yield('css')
@@ -44,18 +47,18 @@
- @yield('title')
+ @yield('title')
-
+{{----}}
- @include('flash::message')
+ @include('installer::flash.message')
@yield('content')
diff --git a/modules/Installer/Resources/views/flash/dbtest.blade.php b/modules/Installer/Resources/views/flash/dbtest.blade.php
new file mode 100644
index 00000000..710dbec1
--- /dev/null
+++ b/modules/Installer/Resources/views/flash/dbtest.blade.php
@@ -0,0 +1,8 @@
+
+
+
+
+
+ {!! $message !!}
+
+
diff --git a/modules/Installer/Resources/views/flash/message.blade.php b/modules/Installer/Resources/views/flash/message.blade.php
index 6834618f..f21e829a 100644
--- a/modules/Installer/Resources/views/flash/message.blade.php
+++ b/modules/Installer/Resources/views/flash/message.blade.php
@@ -1,8 +1,11 @@
-
+@foreach (session('flash_notification', collect())->toArray() as $message)
+
- {!! $message !!}
+ {!! $message['message'] !!}
+@endforeach
+{{ session()->forget('flash_notification') }}
diff --git a/modules/Installer/Resources/views/steps/step1-requirements.blade.php b/modules/Installer/Resources/views/steps/step1-requirements.blade.php
index 093f9592..d5a6f0c5 100644
--- a/modules/Installer/Resources/views/steps/step1-requirements.blade.php
+++ b/modules/Installer/Resources/views/steps/step1-requirements.blade.php
@@ -29,6 +29,20 @@
@endforeach
+
+
directory permissions |
+ @foreach($directories as $dir)
+
+ | {!! $dir['dir'] !!} |
+
+ @if($dir['passed'] === true)
+ OK!
+ @else
+ Failed!
+ @endif
+ |
+
+ @endforeach
@if($passed === true)
diff --git a/modules/Installer/Resources/views/steps/step2-db.blade.php b/modules/Installer/Resources/views/steps/step2-db.blade.php
index 4ce0080a..e1e1e614 100644
--- a/modules/Installer/Resources/views/steps/step2-db.blade.php
+++ b/modules/Installer/Resources/views/steps/step2-db.blade.php
@@ -5,7 +5,7 @@
{!! Form::open(['route' => 'installer.envsetup', 'method' => 'POST']) !!}
- | Select Database Type |
+ Select Database Type |
{!! Form::select('db_conn', $db_types, null, ['class' => 'form-control', 'id' => 'db_conn']) !!}
diff --git a/modules/Installer/Services/RequirementsService.php b/modules/Installer/Services/RequirementsService.php
index 9ba34e2f..8c202715 100644
--- a/modules/Installer/Services/RequirementsService.php
+++ b/modules/Installer/Services/RequirementsService.php
@@ -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;
+ }
}
|