From 3bc1b9038d0288f20b530636e495dea3a2305cdf Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Wed, 24 Jan 2024 11:54:29 +0000 Subject: [PATCH] Fix for LDAP syncing with base_dn and location_id and location --- app/Console/Commands/LdapSync.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index e861b9af3..05f60ee4e 100755 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -88,18 +88,20 @@ class LdapSync extends Command /** * if a location ID has been specified, use that OU */ - if ( $this->option('location_id') != '') { + if ( $this->option('location_id') ) { foreach($this->option('location_id') as $location_id){ $location_ou = Location::where('id', '=', $location_id)->value('ldap_ou'); $search_base = $location_ou; Log::debug('Importing users from specified location OU: \"'.$search_base.'\".'); } + } /** - * Otherwise if a manual base DN has been specified, use that + * if a manual base DN has been specified, use that. Allow the Base DN to override + * even if there's a location-based DN - if you picked it, you must have picked it for a reason. */ - } elseif ($this->option('base_dn') != '') { + if ($this->option('base_dn') != '') { $search_base = $this->option('base_dn'); Log::debug('Importing users from specified base DN: \"'.$search_base.'\".'); } @@ -125,14 +127,14 @@ class LdapSync extends Command /* Determine which location to assign users to by default. */ $location = null; // TODO - this would be better called "$default_location", which is more explicit about its purpose - if ($this->option('location') != '') { - if ($location = Location::where('name', '=', $this->option('location'))->first()) { - Log::debug('Location name ' . $this->option('location') . ' passed'); - Log::debug('Importing to ' . $location->name . ' (' . $location->id . ')'); - } + if ($this->option('location') != '') { + if ($location = Location::where('name', '=', $this->option('location'))->first()) { + Log::debug('Location name ' . $this->option('location') . ' passed'); + Log::debug('Importing to ' . $location->name . ' (' . $location->id . ')'); + } - } elseif ($this->option('location_id') != '') { - foreach($this->option('location_id') as $location_id) { + } elseif ($this->option('location_id')) { + foreach($this->option('location_id') as $location_id) { if ($location = Location::where('id', '=', $location_id)->first()) { Log::debug('Location ID ' . $location_id . ' passed'); Log::debug('Importing to ' . $location->name . ' (' . $location->id . ')');