Add to Importer the capacity to search Models only with Model Name since Model Number is not required
This commit is contained in:
parent
d5f6f6cafe
commit
8bd280b416
1 changed files with 10 additions and 2 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,6 @@ 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;
|
|
||||||
$asset_model->update($item);
|
$asset_model->update($item);
|
||||||
$asset_model->save();
|
$asset_model->save();
|
||||||
$this->log('Asset Model Updated');
|
$this->log('Asset Model Updated');
|
||||||
|
|
Loading…
Add table
Reference in a new issue