diff --git a/app/Console/Commands/PaveIt.php b/app/Console/Commands/PaveIt.php index c7a3954dbc..2b9cf0fcf2 100644 --- a/app/Console/Commands/PaveIt.php +++ b/app/Console/Commands/PaveIt.php @@ -72,6 +72,7 @@ class PaveIt extends Command Statuslabel::getQuery()->delete(); Supplier::getQuery()->delete(); Group::getQuery()->delete(); + Import::getQuery()->delete(); DB::statement('delete from accessories_users'); DB::statement('delete from asset_logs'); @@ -131,6 +132,7 @@ class PaveIt extends Command \DB::statement('drop table IF EXISTS throttle'); \DB::statement('drop table IF EXISTS users_groups'); \DB::statement('drop table IF EXISTS users'); + \DB::statement('drop table IF EXISTS imports'); } } } diff --git a/app/Http/Controllers/Api/ImportController.php b/app/Http/Controllers/Api/ImportController.php index 6fdb087274..2ef18b784f 100644 --- a/app/Http/Controllers/Api/ImportController.php +++ b/app/Http/Controllers/Api/ImportController.php @@ -45,7 +45,6 @@ class ImportController extends Controller $results = []; $import = new Import; foreach ($files as $file) { - if (!in_array($file->getMimeType(), array( 'application/vnd.ms-excel', 'text/csv', @@ -53,7 +52,7 @@ class ImportController extends Controller 'text/comma-separated-values', 'text/tsv'))) { $results['error']='File type must be CSV'; - return $results; + return response()->json(Helper::formatStandardApiResponse('error', null, $results['error']), 500); } $date = date('Y-m-d-his'); @@ -132,7 +131,7 @@ class ImportController extends Controller try { unlink(config('app.private_uploads').'/imports/'.$import->file_path); $import->delete(); - return response()->json(Helper::formatStandardApiResponse('success', null, trans('message.import.file_delete_success'))); + 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); } diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 187d7ead54..1604586e0d 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -24,8 +24,10 @@ class AssetImporter extends ItemImporter parent::handle($row); foreach ($this->customFields as $customField) { - if ($this->item['custom_fields'][$customField->db_column_name()] = $this->array_smart_custom_field_fetch($row, $customField)) { - $this->log('Custom Field '. $customField->name.': '.$this->array_smart_custom_field_fetch($row, $customField)); + $customFieldValue = $this->array_smart_custom_field_fetch($row, $customField); + if ($customFieldValue) { + $this->item['custom_fields'][$customField->db_column_name()] = $customFieldValue; + $this->log('Custom Field '. $customField->name.': '.$customFieldValue); } } @@ -87,7 +89,6 @@ class AssetImporter extends ItemImporter $asset->{$custom_field} = $val; } } - if (!$this->testRun) { if ($asset->save()) { $asset->logCreate('Imported using csv importer'); diff --git a/app/Importer/Importer.php b/app/Importer/Importer.php index 8bc0eacf05..3ad02a391e 100644 --- a/app/Importer/Importer.php +++ b/app/Importer/Importer.php @@ -55,7 +55,7 @@ abstract class Importer * ObjectImporter constructor. * @param string $filename */ - public function __construct(string $filename) + public function __construct($filename) { $this->filename = $filename; @@ -91,7 +91,7 @@ abstract class Importer * @param $results * @return array */ - public function normalizeInputArray($results): array + public function normalizeInputArray($results) { $newArray = []; @@ -133,7 +133,7 @@ abstract class Importer public function array_smart_custom_field_fetch(array $array, $key) { $index_name = strtolower($key->name); - return array_key_exists($index_name, $array) ? e(trim($array[$index_name])) : ''; + return array_key_exists($index_name, $array) ? e(trim($array[$index_name])) : false; } protected function log($string) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index fd0c38a301..0f3b1bbbcc 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -101,7 +101,8 @@ class CustomField extends Model public function db_column_name() { - return self::convertUnicodeDbSlug(); + return $this->db_column; + // return self::convertUnicodeDbSlug(); } //mutators for 'format' attribute