Merge pull request #16099 from snipe/add_id_to_locations_importer

Fixed #16097 - added location ID to location importer
This commit is contained in:
snipe 2025-01-20 16:58:24 +00:00 committed by GitHub
commit 5afcd8ddb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 3 deletions

View file

@ -39,6 +39,7 @@ abstract class Importer
* @var array * @var array
*/ */
private $defaultFieldMap = [ private $defaultFieldMap = [
'id' => 'id',
'asset_tag' => 'asset tag', 'asset_tag' => 'asset tag',
'activated' => 'activated', 'activated' => 'activated',
'category' => 'category', 'category' => 'category',

View file

@ -456,14 +456,13 @@ class ItemImporter extends Importer
{ {
if (empty($asset_location)) { if (empty($asset_location)) {
$this->log('No location given, so none created.'); $this->log('No location given, so none created.');
return null; return null;
} }
$location = Location::where(['name' => $asset_location])->first(); $location = Location::where(['name' => $asset_location])->first();
if ($location) { if ($location) {
$this->log('Location '.$asset_location.' already exists'); $this->log('Location '.$asset_location.' already exists');
return $location->id; return $location->id;
} }
// No matching locations in the collection, create a new one. // No matching locations in the collection, create a new one.

View file

@ -38,8 +38,16 @@ class LocationImporter extends ItemImporter
{ {
$editingLocation = false; $editingLocation = false;
$location = Location::where('name', '=', $this->findCsvMatch($row, 'name'))->first(); $location = Location::where('name', '=', $this->findCsvMatch($row, 'name'))->first();
if ($this->findCsvMatch($row, 'id')!='') {
// Override location if an ID was given
\Log::debug('Finding location by ID: '.$this->findCsvMatch($row, 'id'));
$location = Location::find($this->findCsvMatch($row, 'id'));
}
if ($location) { if ($location) {
if (! $this->updating) { if (! $this->updating) {
$this->log('A matching Location '.$this->item['name'].' already exists'); $this->log('A matching Location '.$this->item['name'].' already exists');
@ -95,6 +103,7 @@ class LocationImporter extends ItemImporter
} else { } else {
Log::debug($location->getErrors()); Log::debug($location->getErrors());
$this->logError($location, 'Location "'.$this->item['name'].'"');
return $location->errors; return $location->errors;
} }

View file

@ -329,6 +329,7 @@ class Importer extends Component
]; ];
$this->locations_fields = [ $this->locations_fields = [
'id' => trans('general.id'),
'name' => trans('general.item_name_var', ['item' => trans('general.location')]), 'name' => trans('general.item_name_var', ['item' => trans('general.location')]),
'address' => trans('general.address'), 'address' => trans('general.address'),
'address2' => trans('general.importer.address2'), 'address2' => trans('general.importer.address2'),
@ -400,7 +401,6 @@ class Importer extends Component
'requestable', 'requestable',
'Requestable', 'Requestable',
], ],
'gravatar' => 'gravatar' =>
[ [
'gravatar', 'gravatar',