Skip to content

Commit

Permalink
Merge pull request #8619 from uberbrady/fix_ldap_paging
Browse files Browse the repository at this point in the history
Fixed #8563 - Clean up AdLdap2 integration to better handle paged result-sets
  • Loading branch information
snipe committed Oct 26, 2020
2 parents 89e36db + cce0739 commit a7ecaa6
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions app/Console/Commands/LdapSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,11 @@ private function updateCreateUser(AdldapUser $snipeUser): void
*
* @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 {
$ldapUsers = $this->ldap->getLdapUsers($page);
$ldapUsers = $this->ldap->getLdapUsers();
} catch (Exception $e) {
$this->outputError($e);
exit($e->getMessage());
Expand All @@ -242,15 +241,9 @@ private function processLdapUsers(int $page=0): void
}

// 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);
}

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.
}
}

/**
Expand Down

0 comments on commit a7ecaa6

Please sign in to comment.