Skip to content

A free open source IT asset/license management system

Accept user ID as authoratative field for updates

snipe6c684bccd041
diff --git a/app/Http/Livewire/Importer.php b/app/Http/Livewire/Importer.php
index 29837700ed..94f48fbad2 100644
--- a/app/Http/Livewire/Importer.php
+++ b/app/Http/Livewire/Importer.php
@@ -288,6 +288,7 @@ class Importer extends Component
];
$this->users_fields = [
+ 'id' => trans('general.id'),
'company' => trans('general.company'),
'location' => trans('general.location'),
'department' => trans('general.department'),
diff --git a/app/Importer/UserImporter.php b/app/Importer/UserImporter.php
index 7d8e1a3149..e13d4c4cce 100644
--- a/app/Importer/UserImporter.php
+++ b/app/Importer/UserImporter.php
@@ -42,6 +42,7 @@ class UserImporter extends ItemImporter
public function createUserIfNotExists(array $row)
{
// Pull the records from the CSV to determine their values
+ $this->item['id'] = $this->findCsvMatch($row, 'id');
$this->item['username'] = $this->findCsvMatch($row, 'username');
$this->item['first_name'] = $this->findCsvMatch($row, 'first_name');
$this->item['last_name'] = $this->findCsvMatch($row, 'last_name');
@@ -76,13 +77,18 @@ class UserImporter extends ItemImporter
$user_formatted_array = User::generateFormattedNameFromFullName($user_full_name, Setting::getSettings()->username_format);
$this->item['username'] = $user_formatted_array['username'];
}
-
- $user = User::where('username', $this->item['username'])->first();
+
+ // Check if a numeric ID was passed. If it does, use that above all else.
+ if ((array_key_exists('id', $this->item) && ($this->item['id'] != "") && (is_numeric($this->item['id'])))) {
+ $user = User::find($this->item['id']);
+ } else {
+ $user = User::where('username', $this->item['username'])->first();
+ }
+
if ($user) {
+
if (! $this->updating) {
- $this->log('A matching User '.$this->item['name'].' already exists. ');
\Log::debug('A matching User '.$this->item['name'].' already exists. ');
-
return;
}
$this->log('Updating User');
@@ -109,7 +115,6 @@ class UserImporter extends ItemImporter
$user->fill($this->sanitizeItemForStoring($user));
if ($user->save()) {
- // $user->logCreate('Imported using CSV Importer');
$this->log('User '.$this->item['name'].' was created');
if (($user->email) && ($user->activated == '1')) {