mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
Merge pull request #14752 from snipe/fixes/better_handle_data_file_mismatch_in_user_files
Nicer handling of erroring when filename+log do not match
This commit is contained in:
commit
d3798bf251
|
@ -78,24 +78,28 @@ class UserFilesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function destroy($userId = null, $fileId = null)
|
public function destroy($userId = null, $fileId = null)
|
||||||
{
|
{
|
||||||
$user = User::find($userId);
|
if ($user = User::find($userId)) {
|
||||||
$destinationPath = config('app.private_uploads').'/users';
|
|
||||||
|
$this->authorize('delete', $user);
|
||||||
|
$rel_path = 'private_uploads/users';
|
||||||
|
|
||||||
|
|
||||||
|
if ($log = Actionlog::find($fileId)) {
|
||||||
|
$filename = $log->filename;
|
||||||
|
$log->delete();
|
||||||
|
|
||||||
|
if (Storage::exists($rel_path.'/'.$filename)) {
|
||||||
|
Storage::delete($rel_path.'/'.$filename);
|
||||||
|
return redirect()->back()->with('success', trans('admin/users/message.deletefile.success'));
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($user->id)) {
|
|
||||||
$this->authorize('update', $user);
|
|
||||||
$log = Actionlog::find($fileId);
|
|
||||||
$full_filename = $destinationPath.'/'.$log->filename;
|
|
||||||
if (file_exists($full_filename)) {
|
|
||||||
unlink($destinationPath.'/'.$log->filename);
|
|
||||||
}
|
}
|
||||||
$log->delete();
|
|
||||||
|
|
||||||
|
// The log record doesn't exist somehow
|
||||||
return redirect()->back()->with('success', trans('admin/users/message.deletefile.success'));
|
return redirect()->back()->with('success', trans('admin/users/message.deletefile.success'));
|
||||||
}
|
}
|
||||||
// Prepare the error message
|
|
||||||
$error = trans('admin/users/message.user_not_found', ['id' => $userId]);
|
return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', ['id' => $userId]));
|
||||||
// Redirect to the licence management page
|
|
||||||
return redirect()->route('users.index')->with('error', $error);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue