A free open source IT asset/license management system
fix Paginator (#7157)
Diogenes S. Jesus4c61d330e644
diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.phpindex effab2250b..41bd1a811b 100755--- a/app/Console/Commands/LdapSync.php+++ b/app/Console/Commands/LdapSync.php@@ -25,12 +25,12 @@ class LdapSync extends Command** @var string*/- protected $signature = 'snipeit:ldap-sync- {--location= : A location name }- {--location_id= : A location id}- {--base_dn= : A diffrent base DN to use }- {--summary : Print summary }- {--json_summary : Print summary in json format }+ protected $signature = 'snipeit:ldap-sync+ {--location= : A location name }+ {--location_id= : A location id}+ {--base_dn= : A diffrent base DN to use }+ {--summary : Print summary }+ {--json_summary : Print summary in json format }{--dryrun : Run the sync process but don\'t update the database}';/**@@ -142,7 +142,7 @@ class LdapSync extends Command* @return string*/private function getSummary(): string- {+ {if ($this->option('summary') && !$this->dryrun) {$this->summary->each(function ($item) {if ('ERROR' === $item['status']) {@@ -218,33 +218,29 @@ class LdapSync extends Command** @param int $page The page to get the result set*/- private function processLdapUsers(int $page=0): void- {- try {- $ldapUsers = $this->ldap->getLdapUsers($page);- } catch (Exception $e) {- $this->outputError($e);- exit($e->getMessage());- }-- if (0 == $ldapUsers->count()) {- $msg = 'ERROR: No users found!';- Log::error($msg);- if ($this->dryrun) {- $this->error($msg);- }- exit($msg);- }-- // Process each individual users- foreach ($ldapUsers as $user) {- $this->updateCreateUser($user);- }-- if ($ldapUsers->getCurrentPage() < $ldapUsers->getPages()) {- $this->processLdapUsers($ldapUsers->getCurrentPage() + 1);- }- }+ private function processLdapUsers(): void+ {+ try {+ $ldapUsers = $this->ldap->getLdapUsers();+ } catch (Exception $e) {+ $this->outputError($e);+ exit($e->getMessage());+ }++ if (0 == count($ldapUsers)) {+ $msg = 'ERROR: No users found!';+ Log::error($msg);+ if ($this->dryrun) {+ $this->error($msg);+ }+ exit($msg);+ }++ // Process each individual users+ foreach ($ldapUsers as $user) {+ $this->updateCreateUser($user);+ }+ }/*** Get the mapped locations if a base_dn is provided.diff --git a/app/Services/LdapAd.php b/app/Services/LdapAd.phpindex 7c6f28edf0..fb54771a7e 100644--- a/app/Services/LdapAd.php+++ b/app/Services/LdapAd.php@@ -430,11 +430,9 @@ class LdapAd extends LdapAdConfiguration** @since 5.0.0*- * @param int $page The paged results to get- ** @return \Adldap\Query\Paginator*/- public function getLdapUsers(int $page=0): Paginator+ public function getLdapUsers(): Paginator{$search = $this->ldap->search()->users()->in($this->getBaseDn());@@ -444,6 +442,6 @@ class LdapAd extends LdapAdConfiguration}return $search->select($this->getSelectedFields())- ->paginate(self::PAGE_SIZE, $page);+ ->paginate(self::PAGE_SIZE);}}