Skip to content

A free open source IT asset/license management system

Partial fix for better UI on deleting files

snipe3f394f42c7bd
diff --git a/app/Http/Controllers/Api/ImportController.php b/app/Http/Controllers/Api/ImportController.php
index d8d550501e..4db7aa2171 100644
--- a/app/Http/Controllers/Api/ImportController.php
+++ b/app/Http/Controllers/Api/ImportController.php
@@ -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);
}
+
}
}
diff --git a/resources/lang/en/admin/hardware/message.php b/resources/lang/en/admin/hardware/message.php
index e087cad26f..5e9d939fe9 100644
--- a/resources/lang/en/admin/hardware/message.php
+++ b/resources/lang/en/admin/hardware/message.php
@@ -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.',
),