Reduce IDE errors in App\Http\Controllers\SettingsController

This commit is contained in:
bryanlopezinc 2024-05-29 08:07:49 +01:00
parent 02cdda56e2
commit 5d01a06245

View file

@ -14,22 +14,18 @@ use App\Models\Asset;
use App\Models\User;
use App\Notifications\FirstAdminNotification;
use App\Notifications\MailTest;
use Auth;
use Crypt;
use DB;
use enshrined\svgSanitize\Sanitizer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\Rule;
use Image;
use Input;
use Redirect;
use Response;
use App\Http\Requests\SlackSettingsRequest;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Carbon\Carbon;
/**
* This controller handles all actions related to Settings for
@ -108,7 +104,7 @@ class SettingsController extends Controller
$start_settings['env_exposed'] = true;
}
if (\App::Environment('production') && (true == config('app.debug'))) {
if (App::Environment('production') && (true == config('app.debug'))) {
$start_settings['debug_exposed'] = true;
} else {
$start_settings['debug_exposed'] = false;
@ -642,7 +638,7 @@ class SettingsController extends Controller
['next_audit_date' => DB::raw('DATE_ADD(next_audit_date, INTERVAL '.$audit_diff_months.' MONTH)')]
);
\Log::debug($affected .' assets affected by audit interval update');
Log::debug($affected .' assets affected by audit interval update');
}
@ -1211,7 +1207,7 @@ class SettingsController extends Controller
Storage::delete($path . '/' . $filename);
return redirect()->route('settings.backups.index')->with('success', trans('admin/settings/message.backup.file_deleted'));
} catch (\Exception $e) {
\Log::debug($e);
Log::debug($e);
}
} else {
@ -1223,7 +1219,7 @@ class SettingsController extends Controller
}
// Hell to the no
\Log::warning('User ID '.Auth::user()->id.' is attempting to delete backup file '.$filename.' and is not authorized to.');
Log::warning('User ID '.Auth::user()->id.' is attempting to delete backup file '.$filename.' and is not authorized to.');
return redirect()->route('settings.backups.index')->with('error', trans('general.backup_delete_not_allowed'));
}
@ -1298,7 +1294,7 @@ class SettingsController extends Controller
'--force' => true,
]);
\Log::debug('Attempting to restore from: '. storage_path($path).'/'.$filename);
Log::debug('Attempting to restore from: '. storage_path($path).'/'.$filename);
// run the restore command
Artisan::call('snipeit:restore',
@ -1312,26 +1308,26 @@ class SettingsController extends Controller
$output = Artisan::output();
/* Run migrations */
\Log::debug('Migrating database...');
Log::debug('Migrating database...');
Artisan::call('migrate', ['--force' => true]);
$migrate_output = Artisan::output();
\Log::debug($migrate_output);
Log::debug($migrate_output);
$find_user = DB::table('users')->where('username', $user->username)->exists();
if (!$find_user){
\Log::warning('Attempting to restore user: ' . $user->username);
Log::warning('Attempting to restore user: ' . $user->username);
$new_user = $user->replicate();
$new_user->push();
} else {
\Log::debug('User: ' . $user->username .' already exists.');
Log::debug('User: ' . $user->username .' already exists.');
}
\Log::debug('Logging all users out..');
Log::debug('Logging all users out..');
Artisan::call('snipeit:global-logout', ['--force' => true]);
DB::table('users')->update(['remember_token' => null]);
\Auth::logout();
Auth::logout();
return redirect()->route('login')->with('success', 'Your system has been restored. Please login again.');
@ -1355,7 +1351,7 @@ class SettingsController extends Controller
public function getPurge()
{
\Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE');
Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE');
if (config('app.allow_purge')=='true') {
return view('settings.purge-form');
@ -1376,16 +1372,16 @@ class SettingsController extends Controller
*/
public function postPurge(Request $request)
{
\Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE');
Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE');
if (config('app.allow_purge')=='true') {
\Log::debug('Purging is not allowed via the .env');
Log::debug('Purging is not allowed via the .env');
if (!config('app.lock_passwords')) {
if ($request->input('confirm_purge')=='DELETE') {
\Log::warning('User ID ' . Auth::user()->id . ' initiated a PURGE!');
Log::warning('User ID ' . Auth::user()->id . ' initiated a PURGE!');
// Run a backup immediately before processing
Artisan::call('backup:run');
Artisan::call('snipeit:purge', ['--force' => 'true', '--no-interaction' => true]);
@ -1404,7 +1400,7 @@ class SettingsController extends Controller
}
}
\Log::error('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting to purge deleted data and is not authorized to.');
Log::error('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting to purge deleted data and is not authorized to.');
// Nope.
@ -1447,7 +1443,7 @@ class SettingsController extends Controller
])->notify(new MailTest());
return response()->json(Helper::formatStandardApiResponse('success', null, 'Maiol sent!'));
} catch (Exception $e) {
} catch (\Exception $e) {
return response()->json(Helper::formatStandardApiResponse('success', null, $e->getMessage()));
}
}