Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit b288d0e

Browse files
committed
Update import command with new option
- Added `--filter` option to be able to specify a filter inside the import command - Use `paginate()` to retrieve all users in case results are over 1000. This commit is thanks to @sloan58
1 parent 47002ad commit b288d0e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/Commands/Import.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Import extends Command
1717
*/
1818
protected $signature = 'adldap:import
1919
{user?}
20+
{--filter= : A raw filter for limiting users imported.}
2021
{--log=true : Log successful and unsuccessful imported users.}';
2122

2223
/**
@@ -41,17 +42,25 @@ public function handle()
4142
$adldap->connect();
4243
}
4344

44-
$user = $this->argument('user');
45+
$search = $adldap->search()->users();
4546

46-
if ($user) {
47-
$users = [$adldap->search()->users()->findOrFail($user)];
47+
if ($filter = $this->option('filter')) {
48+
// If the filter option was given, we'll
49+
// insert it into our search query.
50+
$search->rawFilter($filter);
51+
}
52+
53+
if ($user = $this->argument('user')) {
54+
$users = [$search->findOrFail($user)];
4855

4956
$this->info("Found user '{$users[0]->getCommonName()}'. Importing...");
5057
} else {
5158
// Retrieve all users.
52-
$users = $adldap->search()->users()->get();
59+
$users = $search->paginate()->getResults();
60+
61+
$count = count($users);
5362

54-
$this->info("Found {$users->count()} user(s). Starting import...");
63+
$this->info("Found {$count} user(s). Starting import...");
5564
}
5665

5766
$this->info("Successfully imported {$this->import($users)} user(s).");

0 commit comments

Comments
 (0)