Merge pull request #10520 from inietov/fixes/sc-14356/importer_creating_duplicate_asset_models
Fixes an issue where importer is creating duplicate asset models
This commit is contained in:
commit
6d96f96615
2 changed files with 22 additions and 9 deletions
|
@ -178,6 +178,7 @@ class ItemImporter extends Importer
|
||||||
*/
|
*/
|
||||||
public function createOrFetchAssetModel(array $row)
|
public function createOrFetchAssetModel(array $row)
|
||||||
{
|
{
|
||||||
|
$condition = array();
|
||||||
$asset_model_name = $this->findCsvMatch($row, 'asset_model');
|
$asset_model_name = $this->findCsvMatch($row, 'asset_model');
|
||||||
$asset_modelNumber = $this->findCsvMatch($row, 'model_number');
|
$asset_modelNumber = $this->findCsvMatch($row, 'model_number');
|
||||||
// TODO: At the moment, this means we can't update the model number if the model name stays the same.
|
// TODO: At the moment, this means we can't update the model number if the model name stays the same.
|
||||||
|
@ -189,8 +190,16 @@ class ItemImporter extends Importer
|
||||||
} elseif ((empty($asset_model_name)) && (empty($asset_modelNumber))) {
|
} elseif ((empty($asset_model_name)) && (empty($asset_modelNumber))) {
|
||||||
$asset_model_name = 'Unknown';
|
$asset_model_name = 'Unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((!empty($asset_model_name)) && (empty($asset_modelNumber))) {
|
||||||
|
$condition[] = ['name', '=', $asset_model_name];
|
||||||
|
} elseif ((!empty($asset_model_name)) && (!empty($asset_modelNumber))) {
|
||||||
|
$condition[] = ['name', '=', $asset_model_name];
|
||||||
|
$condition[] = ['model_number', '=', $asset_modelNumber];
|
||||||
|
}
|
||||||
|
|
||||||
$editingModel = $this->updating;
|
$editingModel = $this->updating;
|
||||||
$asset_model = AssetModel::where(['name' => $asset_model_name, 'model_number' => $asset_modelNumber])->first();
|
$asset_model = AssetModel::where($condition)->first();
|
||||||
|
|
||||||
if ($asset_model) {
|
if ($asset_model) {
|
||||||
if (! $this->updating) {
|
if (! $this->updating) {
|
||||||
|
@ -201,7 +210,11 @@ class ItemImporter extends Importer
|
||||||
$this->log('Matching Model found, updating it.');
|
$this->log('Matching Model found, updating it.');
|
||||||
$item = $this->sanitizeItemForStoring($asset_model, $editingModel);
|
$item = $this->sanitizeItemForStoring($asset_model, $editingModel);
|
||||||
$item['name'] = $asset_model_name;
|
$item['name'] = $asset_model_name;
|
||||||
$item['model_number'] = $asset_modelNumber;
|
|
||||||
|
if(!empty($asset_modelNumber)){
|
||||||
|
$item['model_number'] = $asset_modelNumber;
|
||||||
|
}
|
||||||
|
|
||||||
$asset_model->update($item);
|
$asset_model->update($item);
|
||||||
$asset_model->save();
|
$asset_model->save();
|
||||||
$this->log('Asset Model Updated');
|
$this->log('Asset Model Updated');
|
||||||
|
|
|
@ -368,18 +368,18 @@ Route::group(['prefix' => 'v1', 'middleware' => 'api'], function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::resource('fields',
|
Route::resource('fieldsets',
|
||||||
Api\CustomFieldsetsController::class,
|
Api\CustomFieldsetsController::class,
|
||||||
['names' =>
|
['names' =>
|
||||||
[
|
[
|
||||||
'index' => 'api.customfields.index',
|
'index' => 'api.fieldsets.index',
|
||||||
'show' => 'api.customfields.show',
|
'show' => 'api.fieldsets.show',
|
||||||
'update' => 'api.customfields.update',
|
'update' => 'api.fieldsets.update',
|
||||||
'store' => 'api.customfields.store',
|
'store' => 'api.fieldsets.store',
|
||||||
'destroy' => 'api.customfields.destroy',
|
'destroy' => 'api.fieldsets.destroy',
|
||||||
],
|
],
|
||||||
'except' => ['create', 'edit'],
|
'except' => ['create', 'edit'],
|
||||||
'parameters' => ['field' => 'field_id'],
|
'parameters' => ['fieldset' => 'fieldset_id'],
|
||||||
]
|
]
|
||||||
); // end custom fieldsets API routes
|
); // end custom fieldsets API routes
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue