@@ -65,7 +65,7 @@ public function handle()
6565 $ this ->info ("Found {$ count } user(s). Importing... " );
6666 }
6767
68- $ this ->info ("Successfully imported {$ this ->import ($ users )} user(s). " );
68+ $ this ->info ("\n Successfully imported / synchronized {$ this ->import ($ users )} user(s). " );
6969 }
7070
7171 /**
@@ -80,32 +80,37 @@ public function import(array $users = [])
8080 {
8181 $ imported = 0 ;
8282
83+ // We need to filter our results to make sure they are
84+ // only users. In some cases, Contact models may be
85+ // returned due the possibility of the
86+ // existing in the same scope.
87+ $ users = collect ($ users )->filter (function ($ user ) {
88+ return $ user instanceof User;
89+ });
90+
91+ $ bar = $ this ->output ->createProgressBar (count ($ users ));
92+
8393 foreach ($ users as $ user ) {
84- if ($ user instanceof User) {
85- try {
86- // Import the user and then save the model.
87- $ model = $ this ->getModelFromAdldap ($ user );
88-
89- if ($ this ->saveModel ($ model ) && $ model ->wasRecentlyCreated ) {
90- // Only increment imported for new models.
91- $ imported ++;
92-
93- // Log the successful import.
94- if ($ this ->isLogging ()) {
95- logger ()->info ("Imported user {$ user ->getCommonName ()}" );
96- }
97- }
98-
99- if ($ this ->isDeleting ()) {
100- $ this ->delete ($ user , $ model );
101- }
102- } catch (\Exception $ e ) {
103- // Log the unsuccessful import.
104- if ($ this ->isLogging ()) {
105- logger ()->error ("Unable to import user {$ user ->getCommonName ()}. {$ e ->getMessage ()}" );
106- }
94+ try {
95+ // Import the user and retrieve it's model.
96+ $ model = $ this ->getModelFromAdldap ($ user );
97+
98+ // Save the returned model.
99+ $ this ->save ($ user , $ model );
100+
101+ if ($ this ->isDeleting ()) {
102+ $ this ->delete ($ user , $ model );
103+ }
104+
105+ $ imported ++;
106+ } catch (\Exception $ e ) {
107+ // Log the unsuccessful import.
108+ if ($ this ->isLogging ()) {
109+ logger ()->error ("Unable to import user {$ user ->getCommonName ()}. {$ e ->getMessage ()}" );
107110 }
108111 }
112+
113+ $ bar ->advance ();
109114 }
110115
111116 return $ imported ;
@@ -181,6 +186,30 @@ public function createModel()
181186 return new $ model ();
182187 }
183188
189+ /**
190+ * Saves the specified user with its model.
191+ *
192+ * @param User $user
193+ * @param Model $model
194+ *
195+ * @return bool
196+ */
197+ protected function save (User $ user , Model $ model )
198+ {
199+ $ imported = false ;
200+
201+ if ($ this ->saveModel ($ model ) && $ model ->wasRecentlyCreated ) {
202+ $ imported = true ;
203+
204+ // Log the successful import.
205+ if ($ this ->isLogging ()) {
206+ logger ()->info ("Imported user {$ user ->getCommonName ()}" );
207+ }
208+ }
209+
210+ return $ imported ;
211+ }
212+
184213 /**
185214 * Soft deletes the specified model if the specified AD account is disabled.
186215 *
0 commit comments