mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04: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();
|
$check = SystemHealth::check();
|
||||||
|
|
||||||
if ($check['system_status'] === false) {
|
if ($check['system_health'] === false) {
|
||||||
return; /* This should never be reached. */
|
return back(); // This should never be reached.
|
||||||
}
|
}
|
||||||
|
|
||||||
$_ENV['APP_KEY'] = config('app.key');
|
$_ENV['APP_KEY'] = config('app.key');
|
||||||
@ -72,39 +72,47 @@ class SetupController extends Controller
|
|||||||
|
|
||||||
$config = '';
|
$config = '';
|
||||||
|
|
||||||
foreach ($_ENV as $key => $val) {
|
try {
|
||||||
if (is_array($val)) {
|
foreach ($_ENV as $key => $val) {
|
||||||
continue;
|
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 {
|
} else {
|
||||||
return response()->json($response_array, 200);
|
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);
|
return response()->json(['message' => $e->getMessage()], 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,14 @@ class SystemHealth
|
|||||||
return $e->getMessage();
|
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));
|
\Log::error(print_r(Mail::failures(), 1));
|
||||||
|
|
||||||
return Mail::failures();
|
return Mail::failures();
|
||||||
|
@ -29,6 +29,13 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@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)
|
@if($check['system_health'] === false)
|
||||||
@include('setup._issues')
|
@include('setup._issues')
|
||||||
@else
|
@else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user