Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 0570268

Browse files
committed
Use function calls rather then facade calls.
2 parents 76c70f2 + eb39792 commit 0570268

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/Commands/Import.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use Adldap\Laravel\Traits\ImportsUsers;
66
use Adldap\Models\User;
7-
use Illuminate\Support\Facades\Log;
8-
use Illuminate\Support\Facades\Auth;
97
use Illuminate\Console\Command;
108

119
class 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

Comments
 (0)