This repository was archived by the owner on Jul 24, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed
Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments