diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 41ceb09eb839..f16632cdf624 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -41,8 +41,8 @@ class SetupController extends Controller { $check = SystemHealth::check(); - if ($check['system_status'] === false) { - return; /* This should never be reached. */ + if ($check['system_health'] === false) { + return back(); // This should never be reached. } $_ENV['APP_KEY'] = config('app.key'); @@ -72,39 +72,47 @@ class SetupController extends Controller $config = ''; - foreach ($_ENV as $key => $val) { - if (is_array($val)) { - continue; + try { + foreach ($_ENV as $key => $val) { + if (is_array($val)) { + continue; + } + if (preg_match('/\s/', $val)) { + $val = "'{$val}'"; + } + $config .= "{$key}={$val}\n"; } - if (preg_match('/\s/', $val)) { - $val = "'{$val}'"; + + /* Write the .env file */ + $filePath = base_path().'/.env'; + $fp = fopen($filePath, 'w'); + fwrite($fp, $config); + fclose($fp); + + /* We need this in some environments that do not have STDIN defined */ + define('STDIN', fopen('php://stdin', 'r')); + + /* Make sure no stale connections are cached */ + \DB::purge('db-ninja-01'); + + /* Run migrations */ + Artisan::call('optimize'); + Artisan::call('migrate', ['--force' => true]); + Artisan::call('db:seed', ['--force' => true]); + + /* Create the first account. */ + if (Account::count() == 0) { + $account = CreateAccount::dispatchNow($request->all()); } - $config .= "{$key}={$val}\n"; + + return redirect('/'); + } catch (\Exception $e) { + info($e->getMessage()); + + return redirect() + ->back() + ->with('setup_error', $e->getMessage()); } - - /* Write the .env file */ - $filePath = base_path().'/.env'; - $fp = fopen($filePath, 'w'); - fwrite($fp, $config); - fclose($fp); - - /* We need this in some environments that do not have STDIN defined */ - define('STDIN', fopen('php://stdin', 'r')); - - /* Make sure no stale connections are cached */ - \DB::purge('db-ninja-01'); - - /* Run migrations */ - Artisan::call('optimize'); - Artisan::call('migrate', ['--force' => true]); - Artisan::call('db:seed', ['--force' => true]); - - /* Create the first account. */ - if (Account::count() == 0) { - $account = CreateAccount::dispatchNow($request->all()); - } - - return redirect('/'); } /** @@ -140,7 +148,9 @@ class SetupController extends Controller } else { return response()->json($response_array, 200); } -` } catch (\Exception $e) { + } catch (\Exception $e) { + info(['message' => $e->getMessage(), 'action' => 'SetupController::checkMail()']); + return response()->json(['message' => $e->getMessage()], 400); } } diff --git a/app/Utils/SystemHealth.php b/app/Utils/SystemHealth.php index 2cc0356a187a..46cfd7ee93b3 100644 --- a/app/Utils/SystemHealth.php +++ b/app/Utils/SystemHealth.php @@ -145,7 +145,14 @@ class SystemHealth return $e->getMessage(); } - if (count(Mail::failures()) > 0) { + /* + * 'message' => 'count(): Parameter must be an array or an object that implements Countable', + * 'action' => 'SetupController::checkMail()', + * + * count(Mail::failures()) + */ + + if (Mail::failures() > 0) { \Log::error(print_r(Mail::failures(), 1)); return Mail::failures(); diff --git a/resources/views/setup/index.blade.php b/resources/views/setup/index.blade.php index c039caeb65e7..bcf808be6c39 100644 --- a/resources/views/setup/index.blade.php +++ b/resources/views/setup/index.blade.php @@ -29,6 +29,13 @@ @endif + @if(session()->has('setup_error')) +
+ Oops, something wen't wrong: +
{{ session('setup_error') }}
+
+ @endif + @if($check['system_health'] === false) @include('setup._issues') @else