Skip to content

Commit cf3ffe9

Browse files
authored
Merge pull request #14782 from bryanlopezinc/ReduceIDeErrors
Reduce IDE errors in App\Http\Controllers\SettingsController
2 parents 02cdda5 + 5d01a06 commit cf3ffe9

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

app/Http/Controllers/SettingsController.php

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,18 @@
1414
use App\Models\User;
1515
use App\Notifications\FirstAdminNotification;
1616
use App\Notifications\MailTest;
17-
use Auth;
18-
use Crypt;
19-
use DB;
20-
use enshrined\svgSanitize\Sanitizer;
2117
use Illuminate\Http\Request;
18+
use Illuminate\Support\Facades\App;
2219
use Illuminate\Support\Facades\Storage;
2320
use Illuminate\Validation\Rule;
24-
use Image;
25-
use Input;
2621
use Redirect;
27-
use Response;
28-
use App\Http\Requests\SlackSettingsRequest;
2922
use Illuminate\Support\Str;
3023
use Illuminate\Support\Facades\Artisan;
24+
use Illuminate\Support\Facades\Auth;
25+
use Illuminate\Support\Facades\Crypt;
26+
use Illuminate\Support\Facades\DB;
27+
use Illuminate\Support\Facades\Log;
3128
use Illuminate\Support\Facades\Validator;
32-
use Carbon\Carbon;
3329

3430
/**
3531
* This controller handles all actions related to Settings for
@@ -108,7 +104,7 @@ public function getSetupIndex()
108104
$start_settings['env_exposed'] = true;
109105
}
110106

111-
if (\App::Environment('production') && (true == config('app.debug'))) {
107+
if (App::Environment('production') && (true == config('app.debug'))) {
112108
$start_settings['debug_exposed'] = true;
113109
} else {
114110
$start_settings['debug_exposed'] = false;
@@ -642,9 +638,9 @@ public function postAlerts(Request $request)
642638
['next_audit_date' => DB::raw('DATE_ADD(next_audit_date, INTERVAL '.$audit_diff_months.' MONTH)')]
643639
);
644640

645-
\Log::debug($affected .' assets affected by audit interval update');
641+
Log::debug($affected .' assets affected by audit interval update');
642+
646643

647-
648644
}
649645

650646
$alert_email = rtrim($request->input('alert_email'), ',');
@@ -1115,11 +1111,11 @@ public function getBackups()
11151111
'filesize' => Setting::fileSizeConvert(Storage::size($backup_files[$f])),
11161112
'modified_value' => $file_timestamp,
11171113
'modified_display' => date($settings->date_display_format.' '.$settings->time_display_format, $file_timestamp),
1118-
1114+
11191115
];
11201116
}
11211117

1122-
1118+
11231119
}
11241120
}
11251121

@@ -1211,7 +1207,7 @@ public function deleteFile($filename = null)
12111207
Storage::delete($path . '/' . $filename);
12121208
return redirect()->route('settings.backups.index')->with('success', trans('admin/settings/message.backup.file_deleted'));
12131209
} catch (\Exception $e) {
1214-
\Log::debug($e);
1210+
Log::debug($e);
12151211
}
12161212

12171213
} else {
@@ -1223,7 +1219,7 @@ public function deleteFile($filename = null)
12231219
}
12241220

12251221
// Hell to the no
1226-
\Log::warning('User ID '.Auth::user()->id.' is attempting to delete backup file '.$filename.' and is not authorized to.');
1222+
Log::warning('User ID '.Auth::user()->id.' is attempting to delete backup file '.$filename.' and is not authorized to.');
12271223
return redirect()->route('settings.backups.index')->with('error', trans('general.backup_delete_not_allowed'));
12281224
}
12291225

@@ -1255,7 +1251,7 @@ public function postUploadBackup(Request $request) {
12551251
$upload_filename = 'uploaded-'.date('U').'-'.Str::slug(pathinfo($request->file('file')->getClientOriginalName(), PATHINFO_FILENAME)).'.zip';
12561252

12571253
Storage::putFileAs('app/backups', $request->file('file'), $upload_filename);
1258-
1254+
12591255
return redirect()->route('settings.backups.index')->with('success', 'File uploaded');
12601256
}
12611257

@@ -1265,10 +1261,10 @@ public function postUploadBackup(Request $request) {
12651261

12661262
} else {
12671263
return redirect()->route('settings.backups.index')->with('error', trans('general.feature_disabled'));
1268-
}
1264+
}
1265+
1266+
12691267

1270-
1271-
12721268
}
12731269

12741270
/**
@@ -1282,7 +1278,7 @@ public function postUploadBackup(Request $request) {
12821278
*/
12831279
public function postRestore($filename = null)
12841280
{
1285-
1281+
12861282
if (! config('app.lock_passwords')) {
12871283
$path = 'app/backups';
12881284

@@ -1298,43 +1294,43 @@ public function postRestore($filename = null)
12981294
'--force' => true,
12991295
]);
13001296

1301-
\Log::debug('Attempting to restore from: '. storage_path($path).'/'.$filename);
1297+
Log::debug('Attempting to restore from: '. storage_path($path).'/'.$filename);
13021298

13031299
// run the restore command
1304-
Artisan::call('snipeit:restore',
1300+
Artisan::call('snipeit:restore',
13051301
[
1306-
'--force' => true,
1307-
'--no-progress' => true,
1302+
'--force' => true,
1303+
'--no-progress' => true,
13081304
'filename' => storage_path($path).'/'.$filename
13091305
]);
13101306

13111307
// If it's greater than 300, it probably worked
13121308
$output = Artisan::output();
13131309

13141310
/* Run migrations */
1315-
\Log::debug('Migrating database...');
1311+
Log::debug('Migrating database...');
13161312
Artisan::call('migrate', ['--force' => true]);
13171313
$migrate_output = Artisan::output();
1318-
\Log::debug($migrate_output);
1314+
Log::debug($migrate_output);
13191315

13201316
$find_user = DB::table('users')->where('username', $user->username)->exists();
1321-
1317+
13221318
if (!$find_user){
1323-
\Log::warning('Attempting to restore user: ' . $user->username);
1319+
Log::warning('Attempting to restore user: ' . $user->username);
13241320
$new_user = $user->replicate();
13251321
$new_user->push();
13261322
} else {
1327-
\Log::debug('User: ' . $user->username .' already exists.');
1323+
Log::debug('User: ' . $user->username .' already exists.');
13281324
}
13291325

1330-
\Log::debug('Logging all users out..');
1326+
Log::debug('Logging all users out..');
13311327
Artisan::call('snipeit:global-logout', ['--force' => true]);
13321328

13331329
DB::table('users')->update(['remember_token' => null]);
1334-
\Auth::logout();
1330+
Auth::logout();
13351331

13361332
return redirect()->route('login')->with('success', 'Your system has been restored. Please login again.');
1337-
1333+
13381334
} else {
13391335
return redirect()->route('settings.backups.index')->with('error', trans('admin/settings/message.backup.file_not_found'));
13401336
}
@@ -1355,7 +1351,7 @@ public function postRestore($filename = null)
13551351
public function getPurge()
13561352
{
13571353

1358-
\Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE');
1354+
Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE');
13591355

13601356
if (config('app.allow_purge')=='true') {
13611357
return view('settings.purge-form');
@@ -1376,16 +1372,16 @@ public function getPurge()
13761372
*/
13771373
public function postPurge(Request $request)
13781374
{
1379-
\Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE');
1375+
Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE');
13801376

13811377
if (config('app.allow_purge')=='true') {
1382-
\Log::debug('Purging is not allowed via the .env');
1378+
Log::debug('Purging is not allowed via the .env');
13831379

13841380
if (!config('app.lock_passwords')) {
13851381

13861382
if ($request->input('confirm_purge')=='DELETE') {
13871383

1388-
\Log::warning('User ID ' . Auth::user()->id . ' initiated a PURGE!');
1384+
Log::warning('User ID ' . Auth::user()->id . ' initiated a PURGE!');
13891385
// Run a backup immediately before processing
13901386
Artisan::call('backup:run');
13911387
Artisan::call('snipeit:purge', ['--force' => 'true', '--no-interaction' => true]);
@@ -1404,7 +1400,7 @@ public function postPurge(Request $request)
14041400
}
14051401
}
14061402

1407-
\Log::error('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting to purge deleted data and is not authorized to.');
1403+
Log::error('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting to purge deleted data and is not authorized to.');
14081404

14091405

14101406
// Nope.
@@ -1447,7 +1443,7 @@ public function ajaxTestEmail()
14471443
])->notify(new MailTest());
14481444

14491445
return response()->json(Helper::formatStandardApiResponse('success', null, 'Maiol sent!'));
1450-
} catch (Exception $e) {
1446+
} catch (\Exception $e) {
14511447
return response()->json(Helper::formatStandardApiResponse('success', null, $e->getMessage()));
14521448
}
14531449
}

0 commit comments

Comments
 (0)