A free open source IT asset/license management system
Merge pull request #14441 from Godmartinz/ldap_location-resync
snipe787340b987ce
diff --cc app/Console/Commands/LdapSync.phpindex 9f4281bd46,7fcbc8eb07..8550340a21mode 100644,100755..100644--- a/app/Console/Commands/LdapSync.php+++ b/app/Console/Commands/LdapSync.php@@@ -387,47 -374,46 +388,49 @@@ class LdapSync extends Comman'4260352', // 0x410200 NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD, DONT_REQ_PREAUTH'1049088', // 0x100200 NORMAL_ACCOUNT, NOT_DELEGATED'1114624', // 0x110200 NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD, NOT_DELEGATED,- ];- $user->activated = (in_array($results[$i]['useraccountcontrol'][0], $enabled_accounts)) ? 1 : 0;+ ];+ $user->activated = (in_array($results[$i]['useraccountcontrol'][0], $enabled_accounts)) ? 1 : 0;// If we're not using AD, and there isn't an activated flag set, activate all users- } /* implied 'else' here - leave the $user->activated flag alone. Newly-created accounts will be active.- already-existing accounts will be however the administrator has set them */+ } /* implied 'else' here - leave the $user->activated flag alone. Newly-created accounts will be active.+ already-existing accounts will be however the administrator has set them */- if ($item['ldap_location_override'] == true) {- $user->location_id = $item['location_id'];- } elseif ((isset($location)) && (! empty($location))) {- if ((is_array($location)) && (array_key_exists('id', $location))) {- $user->location_id = $location['id'];- } elseif (is_object($location)) {- $user->location_id = $location->id;- }+ if ($item['ldap_location_override'] == true) {+ $user->location_id = $item['location_id'];+ } elseif ((isset($location)) && (!empty($location))) {+ if ((is_array($location)) && (array_key_exists('id', $location))) {+ $user->location_id = $location['id'];+ } elseif (is_object($location)) {+ $user->location_id = $location->id; //THIS is the magic line, this should do it.+ }+ }+ // TODO - should we be NULLING locations if $location is really `null`, and that's what we came up with?+ // will that conflict with any overriding setting that the user set? Like, if they moved someone from+ // the 'null' location to somewhere, we wouldn't want to try to override that, right?+ $location = null;+ $user->ldap_import = 1;++ $errors = '';++ if ($user->save()) {+ $item['note'] = $item['createorupdate'];+ $item['status'] = 'success';+ if ($item['createorupdate'] === 'created' && $ldap_default_group) {+ $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]);- $user->ldap_import = 1;-- $errors = '';-- if ($user->save()) {- $item['note'] = $item['createorupdate'];- $item['status'] = 'success';- if ( $item['createorupdate'] === 'created' && $ldap_default_group) {- $user->groups()->attach($ldap_default_group);- }-- } else {- foreach ($user->getErrors()->getMessages() as $key => $err) {- $errors .= $err[0];- }- $item['note'] = $errors;- $item['status'] = 'error';+ } else {+ foreach ($user->getErrors()->getMessages() as $key => $err) {+ $errors .= $err[0];}+ $item['note'] = $errors;+ $item['status'] = 'error';+ }- array_push($summary, $item);+ array_push($summary, $item);}if ($this->option('summary')) {