mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Accept user ID as authoratative field for updates
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
157a4341ea
commit
6c684bccd0
|
@ -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'),
|
||||
|
|
|
@ -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');
|
||||
|
@ -77,12 +78,17 @@ class UserImporter extends ItemImporter
|
|||
$this->item['username'] = $user_formatted_array['username'];
|
||||
}
|
||||
|
||||
// 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. ');
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
|
||||
if (! $this->updating) {
|
||||
\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')) {
|
||||
|
|
Loading…
Reference in a new issue