1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Handling setup errors (#3567)

- Removed count() for Mail::failures()
- Added new error alert if occurs
- Fix syntax error
- Apply php-cs-fix
This commit is contained in:
Benjamin Beganović 2020-03-31 09:00:24 +02:00 committed by GitHub
parent 79fb806967
commit 9f563d2fbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 34 deletions

View File

@ -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);
}
}

View File

@ -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();

View File

@ -29,6 +29,13 @@
</div>
@endif
@if(session()->has('setup_error'))
<div class="alert alert-failure mt-4">
<span class="font-bold">Oops, something wen't wrong:</span>
<pre class="bg-white p-3 mt-2 rounded overflow-y-scroll">{{ session('setup_error') }}</pre>
</div>
@endif
@if($check['system_health'] === false)
@include('setup._issues')
@else