Skip to content

A free open source IT asset/license management system

Check for empty headers in import

snipe0fd940ffa420
diff --git a/app/Http/Requests/ItemImportRequest.php b/app/Http/Requests/ItemImportRequest.php
index b25522e786..fdbb5e76f8 100644
--- a/app/Http/Requests/ItemImportRequest.php
+++ b/app/Http/Requests/ItemImportRequest.php
@@ -43,6 +43,20 @@ class ItemImportRequest extends FormRequest
$import->save();
$fieldMappings=[];
if ($import->field_map) {
+
+ // This checks to make sure the field header has been mapped.
+ // If it hasn't been, it will throw an array_flip error
+ foreach ($import->field_map as $field => $fieldValue) {
+ $errorMessage = null;
+
+ if(is_null($fieldValue)){
+ $errorMessage = 'All import fields must be mapped.';
+ $this->errorCallback($import, $field, $errorMessage);
+
+ return $this->errors;
+ }
+ }
+
// We submit as csv field: column, but the importer is happier if we flip it here.
$fieldMappings = array_change_key_case(array_flip($import->field_map), CASE_LOWER);
// dd($fieldMappings);