From 049b9c542b09f0c931bccda99480c94a0bb641bc Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Thu, 9 Jan 2025 13:43:59 +0000 Subject: [PATCH] Conditionally update assets when user's location moves via LDAP --- app/Console/Commands/LdapSync.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index e57fab19abb..c7efa967a4b 100644 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -427,7 +427,13 @@ public function handle() $user->groups()->attach($ldap_default_group); } //updates assets location based on user's location - Asset::where('assigned_to', '=', $user->id)->where('assigned_type', '=', User::class)->update(['location_id' => $user->location_id]); + if ($user->wasChanged('location_id')) { + foreach ($user->assets as $asset) { + $asset->location_id = $user->location_id; + // TODO: somehow add note? "Asset Location Changed because of thing" + $asset->save(); + } + } } else { foreach ($user->getErrors()->getMessages() as $key => $err) {