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
15
15
*
16
16
* @var string
17
17
*/
18
- protected $ signature = 'adldap:import ' ;
18
+ protected $ signature = 'adldap:import
19
+ {user?}
20
+ {--log=true : Log successful and unsuccessful imported users.} ' ;
19
21
20
22
/**
21
23
* The console command description.
@@ -39,8 +41,14 @@ public function handle()
39
41
$ adldap ->connect ();
40
42
}
41
43
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
+ }
44
52
45
53
$ this ->info ("Successfully imported {$ this ->import ($ users )} user(s). " );
46
54
}
@@ -68,11 +76,17 @@ public function import($users = [])
68
76
$ imported ++;
69
77
70
78
// 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
+ }
72
82
}
73
83
} catch (\Exception $ e ) {
84
+ $ message = "Unable to import user {$ user ->getCommonName ()}. {$ e ->getMessage ()}" ;
85
+
74
86
// 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
+ }
76
90
}
77
91
}
78
92
}
You can’t perform that action at this time.
0 commit comments