Skip to content

Commit 80550c9

Browse files
Fixing grokability#15064 - to not fail ldap sync on single data issue with ldap manager
1 parent 0e61d0b commit 80550c9

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

app/Console/Commands/LdapSync.php

+20-13
Original file line numberDiff line numberDiff line change
@@ -320,22 +320,29 @@ public function handle()
320320
]
321321
];
322322
}
323-
323+
324+
$add_manager_to_cache = true;
324325
if ($ldap_manager["count"] > 0) {
325-
326-
// Get the Manager's username
327-
// PHP LDAP returns every LDAP attribute as an array, and 90% of the time it's an array of just one item. But, hey, it's an array.
328-
$ldapManagerUsername = $ldap_manager[0][$ldap_map["username"]][0];
329-
330-
// Get User from Manager username.
331-
$ldap_manager = User::where('username', $ldapManagerUsername)->first();
332-
333-
if ($ldap_manager && isset($ldap_manager->id)) {
334-
// Link user to manager id.
335-
$user->manager_id = $ldap_manager->id;
326+
try {
327+
// Get the Manager's username
328+
// PHP LDAP returns every LDAP attribute as an array, and 90% of the time it's an array of just one item. But, hey, it's an array.
329+
$ldapManagerUsername = $ldap_manager[0][$ldap_map["username"]][0];
330+
331+
// Get User from Manager username.
332+
$ldap_manager = User::where('username', $ldapManagerUsername)->first();
333+
334+
if ($ldap_manager && isset($ldap_manager->id)) {
335+
// Link user to manager id.
336+
$user->manager_id = $ldap_manager->id;
337+
}
338+
} catch (\Exception $e) {
339+
$add_manager_to_cache = false;
340+
\Log::warning('Handling ldap manager ' . $item['manager'] . ' caused an exception: ' . $e->getMessage() . '. Continuing synchronization.');
336341
}
337342
}
338-
$manager_cache[$item['manager']] = $ldap_manager && isset($ldap_manager->id) ? $ldap_manager->id : null; // Store results in cache, even if 'failed'
343+
if ($add_manager_to_cache) {
344+
$manager_cache[$item['manager']] = $ldap_manager && isset($ldap_manager->id) ? $ldap_manager->id : null; // Store results in cache, even if 'failed'
345+
}
339346

340347
}
341348
}

0 commit comments

Comments
 (0)