mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
fix Paginator (#7157)
This commit is contained in:
parent
c6039cbc1d
commit
4c61d330e6
|
@ -25,12 +25,12 @@ class LdapSync extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'snipeit:ldap-sync
|
protected $signature = 'snipeit:ldap-sync
|
||||||
{--location= : A location name }
|
{--location= : A location name }
|
||||||
{--location_id= : A location id}
|
{--location_id= : A location id}
|
||||||
{--base_dn= : A diffrent base DN to use }
|
{--base_dn= : A diffrent base DN to use }
|
||||||
{--summary : Print summary }
|
{--summary : Print summary }
|
||||||
{--json_summary : Print summary in json format }
|
{--json_summary : Print summary in json format }
|
||||||
{--dryrun : Run the sync process but don\'t update the database}';
|
{--dryrun : Run the sync process but don\'t update the database}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,7 +142,7 @@ class LdapSync extends Command
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getSummary(): string
|
private function getSummary(): string
|
||||||
{
|
{
|
||||||
if ($this->option('summary') && !$this->dryrun) {
|
if ($this->option('summary') && !$this->dryrun) {
|
||||||
$this->summary->each(function ($item) {
|
$this->summary->each(function ($item) {
|
||||||
if ('ERROR' === $item['status']) {
|
if ('ERROR' === $item['status']) {
|
||||||
|
@ -218,33 +218,29 @@ class LdapSync extends Command
|
||||||
*
|
*
|
||||||
* @param int $page The page to get the result set
|
* @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());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == $ldapUsers->count()) {
|
if (0 == count($ldapUsers)) {
|
||||||
$msg = 'ERROR: No users found!';
|
$msg = 'ERROR: No users found!';
|
||||||
Log::error($msg);
|
Log::error($msg);
|
||||||
if ($this->dryrun) {
|
if ($this->dryrun) {
|
||||||
$this->error($msg);
|
$this->error($msg);
|
||||||
}
|
}
|
||||||
exit($msg);
|
exit($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process each individual users
|
// Process each individual users
|
||||||
foreach ($ldapUsers as $user) {
|
foreach ($ldapUsers as $user) {
|
||||||
$this->updateCreateUser($user);
|
$this->updateCreateUser($user);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ($ldapUsers->getCurrentPage() < $ldapUsers->getPages()) {
|
|
||||||
$this->processLdapUsers($ldapUsers->getCurrentPage() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the mapped locations if a base_dn is provided.
|
* Get the mapped locations if a base_dn is provided.
|
||||||
|
|
|
@ -430,11 +430,9 @@ class LdapAd extends LdapAdConfiguration
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param int $page The paged results to get
|
|
||||||
*
|
|
||||||
* @return \Adldap\Query\Paginator
|
* @return \Adldap\Query\Paginator
|
||||||
*/
|
*/
|
||||||
public function getLdapUsers(int $page=0): Paginator
|
public function getLdapUsers(): Paginator
|
||||||
{
|
{
|
||||||
$search = $this->ldap->search()->users()->in($this->getBaseDn());
|
$search = $this->ldap->search()->users()->in($this->getBaseDn());
|
||||||
|
|
||||||
|
@ -444,6 +442,6 @@ class LdapAd extends LdapAdConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
return $search->select($this->getSelectedFields())
|
return $search->select($this->getSelectedFields())
|
||||||
->paginate(self::PAGE_SIZE, $page);
|
->paginate(self::PAGE_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue