mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-23 12:44:12 -08:00
Importer fixes v2 (#3524)
* Pave the imports table * Format error response if file is the wrong type. * If a custom field doesn't exist, don't insert a blank string into the custom fields table * CustomField::db_column_name can return the stored name in the db. It's slugified when that value is set initially. This fixes a weird issue where _1 was replaced with _xx
This commit is contained in:
parent
f6be7caaeb
commit
e9b056f66c
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue