Updated SetupController.php

This commit is contained in:
Lee Ween Jiann 2021-04-22 11:12:48 +08:00
parent ddf449001d
commit 062fe152f5

View File

@ -47,8 +47,9 @@ class SetupController extends Controller
{ {
$check = SystemHealth::check(false); $check = SystemHealth::check(false);
if ($check['system_health'] == true && $check['simple_db_check'] && Schema::hasTable('accounts') && $account = Account::all()->first()) if ($check['system_health'] == true && $check['simple_db_check'] && Schema::hasTable('accounts') && $account = Account::all()->first()) {
return redirect('/'); return redirect('/');
}
// not sure if we really need this. // not sure if we really need this.
// if(File::exists(base_path('.env'))) // if(File::exists(base_path('.env')))
@ -124,20 +125,22 @@ class SetupController extends Controller
'MAIL_PASSWORD' => $request->input('mail_password'), 'MAIL_PASSWORD' => $request->input('mail_password'),
'NINJA_ENVIRONMENT' => 'selfhost', 'NINJA_ENVIRONMENT' => 'selfhost',
'DB_CONNECTION' => 'db-ninja-01',
]; ];
if(config('ninja.preconfigured_install')){ if (config('ninja.db.multi_db_enabled')) {
// Database connection was already configured. Don't let the user override it. $env_values['DB_CONNECTION'] = 'db-ninja-01';
unset($env_values['DB_HOST1']); }
unset($env_values['DB_PORT1']);
unset($env_values['DB_DATABASE1']); if (config('ninja.preconfigured_install')) {
unset($env_values['DB_USERNAME1']); // Database connection was already configured. Don't let the user override it.
unset($env_values['DB_PASSWORD1']); unset($env_values['DB_HOST1']);
} unset($env_values['DB_PORT1']);
unset($env_values['DB_DATABASE1']);
unset($env_values['DB_USERNAME1']);
unset($env_values['DB_PASSWORD1']);
}
try { try {
foreach ($env_values as $property => $value) { foreach ($env_values as $property => $value) {
$this->updateEnvironmentProperty($property, $value); $this->updateEnvironmentProperty($property, $value);
} }
@ -149,8 +152,9 @@ class SetupController extends Controller
DB::purge('db-ninja-01'); DB::purge('db-ninja-01');
/* Run migrations */ /* Run migrations */
if(!config('ninja.disable_auto_update')) if (!config('ninja.disable_auto_update')) {
Artisan::call('optimize'); Artisan::call('optimize');
}
Artisan::call('migrate', ['--force' => true]); Artisan::call('migrate', ['--force' => true]);
Artisan::call('db:seed', ['--force' => true]); Artisan::call('db:seed', ['--force' => true]);
@ -168,7 +172,6 @@ class SetupController extends Controller
return redirect('/'); return redirect('/');
} catch (Exception $e) { } catch (Exception $e) {
nlog($e->getMessage()); nlog($e->getMessage());
info($e->getMessage()); info($e->getMessage());
@ -273,13 +276,18 @@ class SetupController extends Controller
public function update() public function update()
{ {
if( Ninja::isNinja() || !request()->has('secret') || (request()->input('secret') != config('ninja.update_secret')) ) if ( Ninja::isNinja() || !request()->has('secret') || (request()->input('secret') != config('ninja.update_secret')) ) {
return redirect('/'); return redirect('/');
}
$cacheCompiled = base_path('bootstrap/cache/compiled.php'); $cacheCompiled = base_path('bootstrap/cache/compiled.php');
if (file_exists($cacheCompiled)) { unlink ($cacheCompiled); } if (file_exists($cacheCompiled)) {
unlink ($cacheCompiled);
}
$cacheServices = base_path('bootstrap/cache/services.php'); $cacheServices = base_path('bootstrap/cache/services.php');
if (file_exists($cacheServices)) { unlink ($cacheServices); } if (file_exists($cacheServices)) {
unlink ($cacheServices);
}
Artisan::call('clear-compiled'); Artisan::call('clear-compiled');
Artisan::call('cache:clear'); Artisan::call('cache:clear');