Better handling if there was no file uploaded

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2021-11-10 01:43:45 -08:00
parent 856b9294f8
commit 457c6080cc

View file

@ -1150,6 +1150,9 @@ class SettingsController extends Controller
public function postUploadBackup(Request $request) { public function postUploadBackup(Request $request) {
if (!$request->hasFile('file')) {
return redirect()->route('settings.backups.index')->with('error', 'No file uploaded');
} else {
$max_file_size = Helper::file_upload_max_size(); $max_file_size = Helper::file_upload_max_size();
$rules = [ $rules = [
@ -1160,21 +1163,19 @@ class SettingsController extends Controller
if ($validator->passes()) { if ($validator->passes()) {
if ($request->hasFile('file')) {
$upload_filename = 'uploaded-'.date('U').'-'.Str::slug(pathinfo($request->file('file')->getClientOriginalName(), PATHINFO_FILENAME)).'.zip'; $upload_filename = 'uploaded-'.date('U').'-'.Str::slug(pathinfo($request->file('file')->getClientOriginalName(), PATHINFO_FILENAME)).'.zip';
Storage::putFileAs('app/backups', $request->file('file'), $upload_filename); Storage::putFileAs('app/backups', $request->file('file'), $upload_filename);
return redirect()->route('settings.backups.index')->with('success', 'File uploaded'); return redirect()->route('settings.backups.index')->with('success', 'File uploaded');
} else {
return redirect()->route('settings.backups.index')->with('error', 'No file uploaded');
}
} else { } else {
return redirect()->route('settings.backups.index')->withErrors($request->getErrors()); return redirect()->route('settings.backups.index')->withErrors($request->getErrors());
} }
}
} }
@ -1198,6 +1199,12 @@ class SettingsController extends Controller
// grab the user's info so we can make sure they exist in the system // grab the user's info so we can make sure they exist in the system
$user = User::find(Auth::user()->id); $user = User::find(Auth::user()->id);
// TODO: run a backup
// TODO: add db:wipe
// run the restore command // run the restore command
Artisan::call('snipeit:restore', Artisan::call('snipeit:restore',
[ [
@ -1212,15 +1219,21 @@ class SettingsController extends Controller
// If it's greater than 300, it probably worked // If it's greater than 300, it probably worked
if (strlen($output) > 300) { if (strlen($output) > 300) {
return redirect()->route('settings.backups.index')->with('success', 'Your system has been restored.'); return redirect()->route('settings.backups.index')->with('success', 'Your system has been restored.');
} else { } else {
return redirect()->route('settings.backups.index')->with('error', $output); return redirect()->route('settings.backups.index')->with('error', $output);
} }
//dd($output); //dd($output);
// insert the user if they are not there in the old one // TODO: insert the user if they are not there in the old one
// log the user out // log the user out
// \Auth::logout();
} else { } else {
return redirect()->route('settings.backups.index')->with('error', trans('admin/settings/message.backup.file_not_found')); return redirect()->route('settings.backups.index')->with('error', trans('admin/settings/message.backup.file_not_found'));
} }