From dbbb7680d9d92ab42ffcca825fd93ff6cc3e5f89 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 9 Jul 2020 21:12:50 -0700 Subject: [PATCH] A few more fixes for the cli MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not check out a piece of software if it’s already been checked out to the user --- .../Commands/CheckoutLicenseToAllUsers.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/CheckoutLicenseToAllUsers.php b/app/Console/Commands/CheckoutLicenseToAllUsers.php index 1421876da4..0855e5d084 100644 --- a/app/Console/Commands/CheckoutLicenseToAllUsers.php +++ b/app/Console/Commands/CheckoutLicenseToAllUsers.php @@ -51,11 +51,12 @@ class CheckoutLicenseToAllUsers extends Command } - 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. '); @@ -68,6 +69,16 @@ class CheckoutLicenseToAllUsers extends Command } 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');