Merge pull request #11154 from inietov/fixes/username_required_on_import

Fixes Username required on import process
This commit is contained in:
snipe 2022-05-18 11:12:07 -07:00 committed by GitHub
commit 4644f1479b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@
namespace App\Importer; namespace App\Importer;
use App\Models\Department; use App\Models\Department;
use App\Models\Setting;
use App\Models\User; use App\Models\User;
use App\Notifications\WelcomeNotification; use App\Notifications\WelcomeNotification;
@ -60,6 +61,13 @@ class UserImporter extends ItemImporter
if ($this->shouldUpdateField($user_department)) { if ($this->shouldUpdateField($user_department)) {
$this->item['department_id'] = $this->createOrFetchDepartment($user_department); $this->item['department_id'] = $this->createOrFetchDepartment($user_department);
} }
if (is_null($this->item['username']) || $this->item['username'] == "") {
$user_full_name = $this->item['first_name'] . ' ' . $this->item['last_name'];
$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(); $user = User::where('username', $this->item['username'])->first();
if ($user) { if ($user) {
if (! $this->updating) { if (! $this->updating) {