55use Adldap \Models \User ;
66use Adldap \Laravel \Traits \ImportsUsers ;
77use Illuminate \Console \Command ;
8+ use Illuminate \Database \Eloquent \Model ;
89use Symfony \Component \Console \Input \InputOption ;
910use Symfony \Component \Console \Input \InputArgument ;
1011
@@ -95,20 +96,8 @@ public function import(array $users = [])
9596 }
9697 }
9798
98- if (
99- $ this ->isDeleting () &&
100- method_exists ($ model , 'trashed ' ) &&
101- ! $ model ->trashed () &&
102- $ user ->isDisabled ()
103- ) {
104- // If deleting is enabled, the model supports soft deletes, the model
105- // isn't already deleted, and the AD user is disabled, we'll
106- // go ahead and delete the users model.
107- $ model ->delete ();
108-
109- if ($ this ->isLogging ()) {
110- logger ()->info ("Soft-deleted user {$ user ->getCommonName ()}. Their AD user account is disabled. " );
111- }
99+ if ($ this ->isDeleting ()) {
100+ $ this ->delete ($ user , $ model );
112101 }
113102 } catch (\Exception $ e ) {
114103 // Log the unsuccessful import.
@@ -172,13 +161,13 @@ public function getArguments()
172161 public function getOptions ()
173162 {
174163 return [
175- ['filter ' , null , InputOption::VALUE_OPTIONAL , 'The raw filter for limiting users imported. ' ],
164+ ['filter ' , ' -f ' , InputOption::VALUE_OPTIONAL , 'The raw filter for limiting users imported. ' ],
176165
177- ['log ' , true , InputOption::VALUE_OPTIONAL , 'Log successful and unsuccessful imported users. ' ],
166+ ['log ' , ' -l ' , InputOption::VALUE_OPTIONAL , 'Log successful and unsuccessful imported users. ' , ' true ' ],
178167
179- ['connection ' , null , InputOption::VALUE_OPTIONAL , 'The LDAP connection to use to import users. ' ],
168+ ['connection ' , ' -c ' , InputOption::VALUE_OPTIONAL , 'The LDAP connection to use to import users. ' ],
180169
181- ['delete ' , false , InputOption::VALUE_OPTIONAL , 'Soft-delete the users model if the AD user is disabled. ' ],
170+ ['delete ' , ' -d ' , InputOption::VALUE_OPTIONAL , 'Soft-delete the users model if the AD user is disabled. ' , ' false ' ],
182171 ];
183172 }
184173
@@ -191,4 +180,28 @@ public function createModel()
191180
192181 return new $ model ();
193182 }
183+
184+ /**
185+ * Soft deletes the specified model if the specified AD account is disabled.
186+ *
187+ * @param User $user
188+ * @param Model $model
189+ */
190+ protected function delete (User $ user , Model $ model )
191+ {
192+ if (
193+ method_exists ($ model , 'trashed ' ) &&
194+ ! $ model ->trashed () &&
195+ $ user ->isDisabled ()
196+ ) {
197+ // If deleting is enabled, the model supports soft deletes, the model
198+ // isn't already deleted, and the AD user is disabled, we'll
199+ // go ahead and delete the users model.
200+ $ model ->delete ();
201+
202+ if ($ this ->isLogging ()) {
203+ logger ()->info ("Soft-deleted user {$ user ->getCommonName ()}. Their AD user account is disabled. " );
204+ }
205+ }
206+ }
194207}
0 commit comments