Partial fix for better UI on deleting files

Still needs Vue stuff
This commit is contained in:
snipe 2018-08-01 18:01:16 -07:00
parent b2c99c88bb
commit 3f394f42c7
2 changed files with 14 additions and 7 deletions

View file

@ -114,7 +114,7 @@ class ImportController extends Controller
/**
* Processes the specified Import.
*
* @param \App\Import $import
* @param int $import_id
* @return \Illuminate\Http\Response
*/
public function process(ItemImportRequest $request, $import_id)
@ -157,19 +157,25 @@ class ImportController extends Controller
/**
* Remove the specified resource from storage.
*
* @param \App\Import $import
* @param int $import_id
* @return \Illuminate\Http\Response
*/
public function destroy($import_id)
{
$this->authorize('create', Asset::class);
$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')));
} catch (\Exception $e) {
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.import.file_delete_error')), 500);
// 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);
}
}
}

View file

@ -43,11 +43,12 @@ return array(
),
'import' => array(
'error' => 'Some items did not import correctly.',
'errorDetail' => 'The following Items were not imported because of errors.',
'success' => "Your file has been imported",
'error' => 'Some items did not import correctly.',
'errorDetail' => 'The following Items were not imported because of errors.',
'success' => "Your file has been imported",
'file_delete_success' => "Your file has been been successfully deleted",
'file_delete_error' => "The file was unable to be deleted",
'file_delete_error' => "The file was unable to be deleted",
'file_not_deleted_warning' => 'The import record was deleted, however the file was unable to be deleted. Check that the file exists in storage/private_uploads/imports/ and manually delete it.',
),