Sitelet https://github.com/Free2MoveApp/snipe-it/commit/0fd940ffa4204697a0b6659c76c8a6298719ba30
Skip to content

Commit 0fd940f

Browse files
committed
Check for empty headers in import
1 parent 858d382 commit 0fd940f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎app/Http/Requests/ItemImportRequest.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ public function import(Import $import)
4343
$import->save();
4444
$fieldMappings=[];
4545
if ($import->field_map) {
46+
47+
// This checks to make sure the field header has been mapped.
48+
// If it hasn't been, it will throw an array_flip error
49+
foreach ($import->field_map as $field => $fieldValue) {
50+
$errorMessage = null;
51+
52+
if(is_null($fieldValue)){
53+
$errorMessage = 'All import fields must be mapped.';
54+
$this->errorCallback($import, $field, $errorMessage);
55+
56+
return $this->errors;
57+
}
58+
}
59+
4660
// We submit as csv field: column, but the importer is happier if we flip it here.
4761
$fieldMappings = array_change_key_case(array_flip($import->field_map), CASE_LOWER);
4862
// dd($fieldMappings);

0 commit comments

Comments
 (0)