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:
parent
79fb806967
commit
9f563d2fbf
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user