| Total Complexity | 36 |
| Total Lines | 355 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | class InstallerController extends Controller |
||
| 21 | { |
||
| 22 | public function __construct() |
||
| 23 | { |
||
| 24 | $this->middleware('auth'); |
||
| 25 | } |
||
| 26 | |||
| 27 | // Home page for Installer Functions |
||
| 28 | public function index() |
||
| 29 | { |
||
| 30 | // Get the list of system categories |
||
| 31 | $cats = SystemCategories::all(); |
||
| 32 | $sysArr = []; |
||
| 33 | // Populate that list with the matching systems |
||
| 34 | foreach($cats as $cat) |
||
| 35 | { |
||
| 36 | $systems = SystemTypes::where('cat_id', $cat->cat_id)->get(); |
||
|
1 ignored issue
–
show
|
|||
| 37 | if(!$systems->isEmpty()) |
||
| 38 | { |
||
| 39 | foreach($systems as $sys) |
||
| 40 | { |
||
| 41 | $sysArr[$cat->name][] = $sys->name; |
||
|
2 ignored issues
–
show
|
|||
| 42 | } |
||
| 43 | } |
||
| 44 | else |
||
| 45 | { |
||
| 46 | $sysArr[$cat->name] = null; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | return view('installer.index', [ |
||
| 51 | 'sysArr' => $sysArr |
||
| 52 | ]); |
||
| 53 | } |
||
| 54 | |||
| 55 | // Server customization form |
||
| 56 | public function customizeSystem() |
||
| 57 | { |
||
| 58 | return view('installer.form.customize'); |
||
| 59 | } |
||
| 60 | |||
| 61 | // Submit the server customization form |
||
| 62 | public function submitCustom(Request $request) |
||
| 75 | } |
||
| 76 | |||
| 77 | // Upload and submit a new site logo |
||
| 78 | public function submitLogo(Request $request) |
||
| 79 | { |
||
| 80 | $file = $request->file; |
||
| 81 | $fileName = $file->getClientOriginalName(); |
||
| 82 | $filePath = $file->storeAs('img', $fileName, 'public'); |
||
| 83 | |||
| 84 | Settings::where('key', 'app.logo')->update([ |
||
| 85 | 'value' => '/storage/img/'.$fileName |
||
| 86 | ]); |
||
| 87 | |||
| 88 | Log::info('A new company logo has been uploaded by User ID-'.Auth::user()->user_id); |
||
| 89 | |||
| 90 | return 'success'; |
||
| 91 | } |
||
| 92 | |||
| 93 | // Email settings form |
||
| 94 | public function emailSettings() |
||
| 95 | { |
||
| 96 | return view('installer.form.email'); |
||
| 97 | } |
||
| 98 | |||
| 99 | // Send a test email |
||
| 100 | public function sendTestEmail(Request $request) |
||
| 101 | { |
||
| 102 | // Make sure that all of the information properly validates |
||
| 103 | $request->validate([ |
||
| 104 | 'host' => 'required', |
||
| 105 | 'port' => 'required|numeric', |
||
| 106 | 'encryption' => 'required', |
||
| 107 | 'username' => 'required' |
||
| 108 | ]); |
||
| 109 | |||
| 110 | // Temporarily set the email settings |
||
| 111 | config([ |
||
| 112 | 'mail.host' => $request->host, |
||
| 113 | 'mail.port' => $request->port, |
||
| 114 | 'mail.encryption' => $request->encryption, |
||
| 115 | 'mail.username' => $request->username, |
||
| 116 | ]); |
||
| 117 | |||
| 118 | if(!empty($request->password)) |
||
| 119 | { |
||
| 120 | config(['mail.password' => $request->password]); |
||
| 121 | } |
||
| 122 | |||
| 123 | // Try and send the test email |
||
| 124 | try |
||
| 125 | { |
||
| 126 | Log::info('Test Email Successfully Sent to '.Auth::user()->email); |
||
| 127 | Mail::to(Auth::user()->email)->send(new TestEmail()); |
||
| 128 | return 'success'; |
||
| 129 | } |
||
| 130 | catch(Exception $e) |
||
| 131 | { |
||
| 132 | Log::notice('Test Email Failed. Message: '.$e); |
||
| 133 | $msg = '['.$e->getCode().'] "'.$e->getMessage().'" on line '.$e->getTrace()[0]['line'].' of file '.$e->getTrace()[0]['file']; |
||
| 134 | return $msg; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | // Submit the email settings form |
||
| 139 | public function submitEmailSettings(Request $request) |
||
| 140 | { |
||
| 141 | $request->validate([ |
||
| 142 | 'host' => 'required', |
||
| 143 | 'port' => 'required|numeric', |
||
| 144 | 'encryption' => 'required', |
||
| 145 | 'username' => 'required' |
||
| 146 | ]); |
||
| 147 | |||
| 148 | // Update each setting |
||
| 149 | Settings::where('key', 'mail.host')->update(['value' => $request->host]); |
||
| 150 | Settings::where('key', 'mail.port')->update(['value' => $request->port]); |
||
| 151 | Settings::where('key', 'mail.encryption')->update(['value' => $request->encryption]); |
||
| 152 | Settings::where('key', 'mail.username')->update(['value' => $request->username]); |
||
| 153 | if(!empty($request->password)) |
||
| 154 | { |
||
| 155 | Settings::where('key', 'mail.password')->update(['value' => $request->password]); |
||
| 156 | } |
||
| 157 | |||
| 158 | Log::info('Email Settings have been changed by User ID-'.Auth::user()->user_id); |
||
| 159 | return redirect()->back()->with('success', 'Tech Bench Successfully Updated');// |
||
| 160 | } |
||
| 161 | |||
| 162 | // User settings form |
||
| 163 | public function userSettings() |
||
| 169 | ]); |
||
| 170 | } |
||
| 171 | |||
| 172 | // Submit the user settings form |
||
| 173 | public function submitUserSettings(Request $request) |
||
| 174 | { |
||
| 175 | $request->validate([ |
||
| 176 | 'passExpire' => 'required|numeric' |
||
| 177 | ]); |
||
| 178 | |||
| 179 | // Determine if the password expires field is updated |
||
| 180 | $oldExpire = config('users.passExpires'); |
||
| 181 | if($request->passExpire != $oldExpire) |
||
| 182 | { |
||
| 183 | // Update the setting in the database |
||
| 184 | Settings::where('key', 'users.passExpires')->update([ |
||
| 185 | 'value' => $request->passExpire |
||
| 186 | ]); |
||
| 187 | // If the setting is changing from never to xx days, update all users |
||
| 188 | if($request->passExpire == 0) |
||
| 189 | { |
||
| 190 | User::whereNotNull('password_expires')->update([ |
||
| 191 | 'password_expires' => null |
||
| 192 | ]); |
||
| 193 | } |
||
| 194 | else |
||
| 195 | { |
||
| 196 | $newExpire = Carbon::now()->addDays($request->passExpire); |
||
| 197 | User::whereNull('password_expires')->update([ |
||
| 198 | 'password_expires' => $newExpire |
||
| 199 | ]); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | Log::info('User Settings have been changed by User ID-'.Auth::user()->user_id); |
||
| 204 | return redirect()->back()->with('success', 'User Settings Updated'); |
||
| 205 | } |
||
| 206 | |||
| 207 | // Form to create a new Category |
||
| 208 | public function newCat() |
||
| 209 | { |
||
| 210 | return view('installer.form.newCat'); |
||
| 211 | } |
||
| 212 | |||
| 213 | // Submit the new Category |
||
| 214 | public function submitCat(Request $request) |
||
| 215 | { |
||
| 216 | $request->validate([ |
||
| 217 | 'name' => 'required|string|unique:system_categories|regex:/^[a-zA-Z0-9_ ]*$/' |
||
| 218 | ]); |
||
| 219 | |||
| 220 | $cat = SystemCategories::create([ |
||
| 221 | 'name' => $request->name |
||
| 222 | ]); |
||
| 223 | |||
| 224 | Log::info('New System Category Created', ['cat_name' => $request->name, 'user_id' => Auth::user()->user_id]); |
||
| 225 | |||
| 226 | return redirect()->back()->with('success', 'Category Successfully Added. <a href="'.route('installer.newSys', urlencode($cat->name)).'">Add System</a>'); |
||
|
1 ignored issue
–
show
|
|||
| 227 | } |
||
| 228 | |||
| 229 | // Form to add a new system |
||
| 230 | public function newSystem($cat) |
||
| 231 | { |
||
| 232 | $dropDown = SystemCustDataTypes::orderBy('name', 'ASC')->get(); |
||
| 233 | |||
| 234 | return view('installer.form.newSystem', [ |
||
| 235 | 'cat' => $cat, |
||
| 236 | 'dropDown' => $dropDown |
||
| 237 | ]); |
||
| 238 | } |
||
| 239 | |||
| 240 | // Submit the new system |
||
| 241 | public function submitSys($cat, Request $request) |
||
| 242 | { |
||
| 243 | $catName = SystemCategories::where('name', urldecode($cat))->first()->cat_id; |
||
|
1 ignored issue
–
show
|
|||
| 244 | $sysData = SystemTypes::create([ |
||
| 245 | 'cat_id' => $catName, |
||
| 246 | 'name' => $request->name, |
||
| 247 | 'parent_id' => null, |
||
| 248 | 'folder_location' => str_replace(' ', '_', $request->name) |
||
| 249 | ]); |
||
| 250 | $sysID = $sysData->sys_id; |
||
|
1 ignored issue
–
show
|
|||
| 251 | $i = 0; |
||
| 252 | |||
| 253 | foreach($request->custField as $field) |
||
| 254 | { |
||
| 255 | if(!empty($field)) |
||
| 256 | { |
||
| 257 | $id = SystemCustDataTypes::where('name', $field)->first(); |
||
| 258 | |||
| 259 | if(is_null($id)) |
||
| 260 | { |
||
| 261 | $newField = SystemCustDataTypes::create([ |
||
| 262 | 'name' => $field |
||
| 263 | ]); |
||
| 264 | $id = $newField->data_type_id; |
||
|
1 ignored issue
–
show
|
|||
| 265 | } |
||
| 266 | else |
||
| 267 | { |
||
| 268 | $id = $id->data_type_id; |
||
| 269 | } |
||
| 270 | |||
| 271 | SystemCustDataFields::create([ |
||
| 272 | 'sys_id' => $sysID, |
||
| 273 | 'data_type_id' => $id, |
||
| 274 | 'order' => $i |
||
| 275 | ]); |
||
| 276 | |||
| 277 | $i++; |
||
| 278 | } |
||
| 279 | } |
||
| 280 | |||
| 281 | Log::info('New System Created', ['cat_id' => $request->catName, 'sys_name' => $request->name, 'user_id' => Auth::user()->user_id]); |
||
| 282 | |||
| 283 | return redirect()->back()->with('success', 'System Successfully Added');// |
||
| 284 | } |
||
| 285 | |||
| 286 | // Form to edit an existing system |
||
| 287 | public function editSystem($sysName) |
||
| 301 | ]); |
||
| 302 | } |
||
| 303 | |||
| 304 | // Submit the edited system |
||
| 305 | public function submitEditSystem($sysID, Request $request) |
||
| 306 | { |
||
| 307 | $sysName = SystemTypes::find($sysID)->name; |
||
|
1 ignored issue
–
show
|
|||
| 308 | |||
| 309 | // Change the name of the system if it has been modified |
||
| 310 | if($sysName !== $request->name) |
||
| 311 | { |
||
| 375 | } |
||
| 376 | } |
||
| 377 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.