Better handling for deleting imports where the files may have been moved

This commit is contained in:
snipe
2018-08-01 20:49:55 -07:00
parent 9168979d9e
commit f5a5d830a5
7 changed files with 80 additions and 71 deletions
+12 -11
View File
@@ -163,18 +163,19 @@ class ImportController extends Controller
public function destroy($import_id)
{
$this->authorize('create', Asset::class);
$import = Import::find($import_id);
if ($import = Import::find($import_id)) {
try {
// Try to delete the file
unlink(config('app.private_uploads').'/imports/'.$import->file_path);
$import->delete();
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.import.file_delete_success')));
try {
// Try to delete the file
unlink(config('app.private_uploads').'/imports/'.$import->file_path);
$import->delete();
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.import.file_delete_success')));
} catch (\Exception $e) {
// If the file delete didn't work, remove it from the database anyway and return a warning
$import->delete();
return response()->json(Helper::formatStandardApiResponse('warn', null, trans('admin/hardware/message.import.file_not_deleted_warning')), 500);
} catch (\Exception $e) {
// If the file delete didn't work, remove it from the database anyway and return a warning
$import->delete();
return response()->json(Helper::formatStandardApiResponse('warn', null, trans('admin/hardware/message.import.file_not_deleted_warning')), 500);
}
}
}