Clean up AdLdap2 integration to better handle paged result-sets

This commit is contained in:
Brady Wetherington 2020-10-26 12:53:45 -07:00
parent 89e36dbc42
commit cce0739bb7

View file

@ -221,12 +221,11 @@ class LdapSync extends Command
* *
* @since 5.0.0 * @since 5.0.0
* *
* @param int $page The page to get the result set
*/ */
private function processLdapUsers(int $page=0): void private function processLdapUsers(): void
{ {
try { try {
$ldapUsers = $this->ldap->getLdapUsers($page); $ldapUsers = $this->ldap->getLdapUsers();
} catch (Exception $e) { } catch (Exception $e) {
$this->outputError($e); $this->outputError($e);
exit($e->getMessage()); exit($e->getMessage());
@ -242,15 +241,9 @@ class LdapSync extends Command
} }
// Process each individual users // Process each individual users
foreach ($ldapUsers as $user) { foreach ($ldapUsers->getResults() as $user) { // AdLdap2's paginate() method is weird, it gets *everything* and ->getResults() returns *everything*
$this->updateCreateUser($user); $this->updateCreateUser($user);
} }
if ($ldapUsers->getCurrentPage() < $ldapUsers->getPages()-1) {
$current_page = $ldapUsers->getCurrentPage();
unset($ldapUsers); //deliberately unset the variable so we don't OOM
$this->processLdapUsers($current_page + 1); //this recursive call means that the $ldapUsers variable is not going to get GC'ed until everything returns. Blech.
}
} }
/** /**