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

Commit 0bb212d

Browse files
committed
Added ability to disable logging and add specific users
1 parent 7b1de4a commit 0bb212d

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/Commands/Import.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class Import extends Command
1515
*
1616
* @var string
1717
*/
18-
protected $signature = 'adldap:import';
18+
protected $signature = 'adldap:import
19+
{user?}
20+
{--log=true : Log successful and unsuccessful imported users.}';
1921

2022
/**
2123
* The console command description.
@@ -39,8 +41,14 @@ public function handle()
3941
$adldap->connect();
4042
}
4143

42-
// Retrieve all users.
43-
$users = $adldap->search()->users()->get();
44+
$user = $this->argument('user');
45+
46+
if ($user) {
47+
$users = [$adldap->search()->users()->findOrFail($user)];
48+
} else {
49+
// Retrieve all users.
50+
$users = $adldap->search()->users()->get();
51+
}
4452

4553
$this->info("Successfully imported {$this->import($users)} user(s).");
4654
}
@@ -68,11 +76,17 @@ public function import($users = [])
6876
$imported++;
6977

7078
// Log the successful import.
71-
logger()->info("Imported user {$user->getCommonName()}");
79+
if ($this->option('log') == 'true') {
80+
logger()->info("Imported user {$user->getCommonName()}");
81+
}
7282
}
7383
} catch (\Exception $e) {
84+
$message = "Unable to import user {$user->getCommonName()}. {$e->getMessage()}";
85+
7486
// Log the unsuccessful import.
75-
logger()->error("Unable to import user {$user->getCommonName()}. {$e->getMessage()}");
87+
if ($this->option('log') == 'true') {
88+
logger()->error($message);
89+
}
7690
}
7791
}
7892
}

0 commit comments

Comments
 (0)