From bdb0e6c2a3a2213c107c690d56f417deccc7529b Mon Sep 17 00:00:00 2001 From: Fiala06 Date: Mon, 2 Dec 2024 11:07:37 -0800 Subject: [PATCH] Update LdapSync.php Fix for duplicate entries preventing the sync from continuing. SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '13178-6' for key 'PRIMARY' (Connection: mysql, SQL: insert into users_groups (group_id, user_id) values (6, 13178)) --- app/Console/Commands/LdapSync.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index 2338cebf750e..2987b2af5cda 100644 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -424,8 +424,12 @@ public function handle() $item['note'] = $item['createorupdate']; $item['status'] = 'success'; if ($item['createorupdate'] === 'created' && $ldap_default_group) { - $user->groups()->attach($ldap_default_group); + // Check if the relationship already exists + if (!$user->groups()->where('group_id', $ldap_default_group)->exists()) { + $user->groups()->attach($ldap_default_group); + } } + //updates assets location based on user's location Asset::where('assigned_to', '=', $user->id)->update(['location_id' => $user->location_id]);