44
55use Adldap \Laravel \Traits \ImportsUsers ;
66use Adldap \Models \User ;
7- use Illuminate \Support \Facades \Log ;
8- use Illuminate \Support \Facades \Auth ;
97use Illuminate \Console \Command ;
108
119class Import extends Command
@@ -43,10 +41,8 @@ public function handle()
4341
4442 // Retrieve all users.
4543 $ users = $ adldap ->search ()->users ()->get ();
46-
47- $ imported = $ this ->import ($ users );
48-
49- $ this ->info ("Successfully imported {$ imported } user(s). " );
44+
45+ $ this ->info ("Successfully imported {$ this ->import ($ users )} user(s). " );
5046 }
5147
5248 /**
@@ -67,15 +63,16 @@ public function import($users = [])
6763 // Import the user and then save the model.
6864 $ model = $ this ->getModelFromAdldap ($ user );
6965
70- $ this ->saveModel ($ model );
71-
72- $ imported ++;
66+ if ( $ this ->saveModel ($ model ) && $ model -> wasRecentlyCreated ) {
67+ // Only increment imported for new models.
68+ $ imported ++;
7369
74- // Log the successful import.
75- Log::info ("Imported user {$ user ->getCommonName ()}" );
70+ // Log the successful import.
71+ logger ()->info ("Imported user {$ user ->getCommonName ()}" );
72+ }
7673 } catch (\Exception $ e ) {
7774 // Log the unsuccessful import.
78- Log:: error ("Unable to import user {$ user ->getCommonName ()}. {$ e ->getMessage ()}" );
75+ logger ()-> error ("Unable to import user {$ user ->getCommonName ()}. {$ e ->getMessage ()}" );
7976 }
8077 }
8178 }
@@ -88,7 +85,7 @@ public function import($users = [])
8885 */
8986 public function createModel ()
9087 {
91- $ model = Auth:: getProvider ()->getModel ();
88+ $ model = auth ()-> getProvider ()->getModel ();
9289
9390 return new $ model ();
9491 }
0 commit comments