Skip to content

A free open source IT asset/license management system

Fix for LDAP syncing with base_dn and location_id and location

Brady Wetherington3bc1b9038d02
diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php
index e861b9af37..05f60ee4e1 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 . ')');