Small fixes to accessories files handling

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2025-02-10 22:26:00 +00:00
parent b48704b3af
commit c420670ebb

View file

@ -55,11 +55,11 @@ class AccessoriesFilesController extends Controller
} }
return redirect()->route('accessories.show', $accessory->id)->with('error', trans('general.no_files_uploaded')); return redirect()->route('accessories.show', $accessory->id)->withFragment('files')->with('error', trans('general.no_files_uploaded'));
} }
// Prepare the error message // Prepare the error message
return redirect()->route('accessories.index') return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
->with('error', trans('general.file_does_not_exist'));
} }
/** /**
@ -72,30 +72,28 @@ class AccessoriesFilesController extends Controller
*/ */
public function destroy($accessoryId = null, $fileId = null) : RedirectResponse public function destroy($accessoryId = null, $fileId = null) : RedirectResponse
{ {
$accessory = Accessory::find($accessoryId); if ($accessory = Accessory::find($accessoryId)) {
// the asset is valid
if (isset($accessory->id)) {
$this->authorize('update', $accessory); $this->authorize('update', $accessory);
$log = Actionlog::find($fileId);
// Remove the file if one exists if ($log = Actionlog::find($fileId)) {
if (Storage::exists('accessories/'.$log->filename)) {
if (Storage::exists('private_uploads/accessories/'.$log->filename)) {
try { try {
Storage::delete('accessories/'.$log->filename); Storage::delete('private_uploads/accessories/' . $log->filename);
$log->delete();
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
} catch (\Exception $e) { } catch (\Exception $e) {
Log::debug($e); Log::debug($e);
}
}
$log->delete();
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
}
// Redirect to the licence management page
return redirect()->route('accessories.index')->with('error', trans('general.file_does_not_exist')); return redirect()->route('accessories.index')->with('error', trans('general.file_does_not_exist'));
} }
}
}
return redirect()->route('accessories.show', ['accessory' => $accessory])->withFragment('files')->with('error', trans('general.log_record_not_found'));
}
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
}
/** /**
* Allows the selected file to be viewed. * Allows the selected file to be viewed.
@ -124,10 +122,11 @@ class AccessoriesFilesController extends Controller
} }
} }
return redirect()->route('accessories.show', ['accessory' => $accessory])->with('error', trans('general.log_record_not_found')); return redirect()->route('accessories.show', ['accessory' => $accessory])->withFragment('files')->with('error', trans('general.log_record_not_found'));
} }
return redirect()->route('accessories.index')->with('error', trans('general.file_not_found')); return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
} }
} }