This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
InstallController.php
163 lines (138 loc) · 4.85 KB
/
InstallController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace App\Http\Controllers\Admin;
use App\Classes\OTF_DB;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class InstallController extends Controller
{
public function index(Request $request)
{
if (env('VAOS_Setup') != true) {
// Return the view right now
if ($request->query('mode') == 'fresh') {
return view('install.fresh');
} elseif ($request->query('mode') == 'settings') {
$data = $_ENV;
return view('install.settings')->with('data', $data);
} else {
return view('install.welcome');
}
} else {
return redirect('/');
}
}
public function doInstall(Request $request)
{
if (! Schema::hasTable('users')) {
Artisan::call('key:generate');
// Run the database migration
Artisan::call('migrate');
User::create([
'first_name' => $request->input('first_name'),
'last_name' => $request->input('last_name'),
'email' => $request->input('email'),
'password' => bcrypt($request->input('password')),
'username' => $request->input('username'),
'status' => 1,
'admin' => true,
]);
$this->changeEnvironmentVariable('VAOS_Setup', true);
//Removed in the view for the moment
/*if (App::environment('production')) {
Artisan::call('config:cache');
}else{
$this->changeEnvironmentVariable('APP_DEBUG', TRUE);
}*/
$user = User::find(1);
Auth::login($user);
return redirect('/admin');
} else {
return redirect('/');
}
}
public function settings(Request $request)
{
$data = $request->all();
foreach ($data as $key => $value) {
if ($key != '_token') {
if ($key == 'VAOS_ORG_NAME' || $key == 'VAOS_ORG_EMAIL') {
$this->changeEnvironmentVariableSpecial($key, $value);
/*}
#Removed in the view for the moment
elseif ($key == "APP_ENV_Development" || $key == "APP_ENV_Production") {
if ($key == "APP_ENV_Development"){
$value = 'local';
}else{
$value = 'production';
}
$this->changeEnvironmentVariable('APP_ENV', $value);*/
} else {
$this->changeEnvironmentVariable($key, $value);
}
}
}
return redirect('/setup?mode=fresh');
}
public function changeEnvironmentVariable($key, $value)
{
$path = base_path('.env');
if (is_bool(env($key))) {
$old = env($key) ? 'true' : 'false';
$value = $value ? 'true' : 'false';
} else {
$old = env($key);
}
if (file_exists($path)) {
file_put_contents($path, str_replace(
$key.'='.$old, $key.'='.$value, file_get_contents($path)
));
}
}
public function changeEnvironmentVariableSpecial($key, $value)
{
$path = base_path('.env');
$old = env($key);
if (file_exists($path)) {
file_put_contents($path, str_replace(
$key.'='.'"'.$old.'"', $key.'='.'"'.$value.'"',
file_get_contents($path)
));
}
}
public function phpVMSTransfer(Request $request)
{
// Set the database
$oldDB = new OTF_DB([
'database' => $request->input('database'),
'username' => $request->input('username'),
'password' => $request->input('password'),
'prefix' => $request->input('prefix'),
]);
$aircraft = $oldDB->getTable('aircraft')->get();
$users = $oldDB->getTable('pilots')->get();
$pireps = $oldDB->getTable('pireps')->get();
$aircraft = $oldDB->getTable('aircraft')->get();
$aircraft = $oldDB->getTable('aircraft')->get();
$aircraft = $oldDB->getTable('aircraft')->get();
$aircraft = $oldDB->getTable('aircraft')->get();
}
public function importSystem(Request $request)
{
}
public function dbMigrate(Request $request)
{
Artisan::call('migrate');
$request->session()->flash('success', true);
return redirect('/admin/migrations');
}
public function viewMigrations()
{
$migrations = DB::table('migrations')->get();
return view('admin.migrations', ['migrations' => $migrations]);
}
}