4
4
5
5
use Adldap \Laravel \Traits \ImportsUsers ;
6
6
use Adldap \Models \User ;
7
- use Illuminate \Support \Facades \Log ;
8
- use Illuminate \Support \Facades \Auth ;
9
7
use Illuminate \Console \Command ;
10
8
11
9
class Import extends Command
@@ -43,10 +41,8 @@ public function handle()
43
41
44
42
// Retrieve all users.
45
43
$ 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). " );
50
46
}
51
47
52
48
/**
@@ -67,15 +63,16 @@ public function import($users = [])
67
63
// Import the user and then save the model.
68
64
$ model = $ this ->getModelFromAdldap ($ user );
69
65
70
- $ this ->saveModel ($ model );
71
-
72
- $ imported ++;
66
+ if ( $ this ->saveModel ($ model ) && $ model -> wasRecentlyCreated ) {
67
+ // Only increment imported for new models.
68
+ $ imported ++;
73
69
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
+ }
76
73
} catch (\Exception $ e ) {
77
74
// 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 ()}" );
79
76
}
80
77
}
81
78
}
@@ -88,7 +85,7 @@ public function import($users = [])
88
85
*/
89
86
public function createModel ()
90
87
{
91
- $ model = Auth:: getProvider ()->getModel ();
88
+ $ model = auth ()-> getProvider ()->getModel ();
92
89
93
90
return new $ model ();
94
91
}
0 commit comments