Skip to content

Commit

Permalink
A few more fixes for the cli
Browse files Browse the repository at this point in the history
Do not check out a piece of software if it’s already been checked out to the user
  • Loading branch information
snipe committed Jul 10, 2020
1 parent cf0dd5b commit dbbb768
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/Console/Commands/CheckoutLicenseToAllUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public function handle()
}


if (!$license = License::where('id','=',$license_id)->first()) {
if (!$license = License::where('id','=',$license_id)->with('assignedusers')->first()) {
$this->error('Invalid license ID');
return false;
}
$users = User::whereNull('deleted_at')->get();

$users = User::whereNull('deleted_at')->with('licenses')->get();

if ($users->count() > $license->getAvailSeatsCountAttribute()) {
$this->info('You do not have enough free seats to complete this task, so we will check out as many as we can. ');
Expand All @@ -68,6 +69,16 @@ public function handle()
}

foreach ($users as $user) {

// Check to make sure this user doesn't already have this license checked out
// to them

if ($user->licenses->where('id', '=', $license_id)->count()) {
$this->info($user->username .' already has this license checked out to them. Skipping... ');
continue;
}


// If the license is valid, check that there is an available seat
if ($license->availCount()->count() < 1) {
$this->error('ERROR: No available seats');
Expand Down

0 comments on commit dbbb768

Please sign in to comment.