mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 05:47:28 -08:00
A few more fixes for the cli
Do not check out a piece of software if it’s already been checked out to the user
This commit is contained in:
parent
cf0dd5bbad
commit
dbbb7680d9
|
@ -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');
|
$this->error('Invalid license ID');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$users = User::whereNull('deleted_at')->get();
|
|
||||||
|
$users = User::whereNull('deleted_at')->with('licenses')->get();
|
||||||
|
|
||||||
if ($users->count() > $license->getAvailSeatsCountAttribute()) {
|
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. ');
|
$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) {
|
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 the license is valid, check that there is an available seat
|
||||||
if ($license->availCount()->count() < 1) {
|
if ($license->availCount()->count() < 1) {
|
||||||
$this->error('ERROR: No available seats');
|
$this->error('ERROR: No available seats');
|
||||||
|
|
Loading…
Reference in a new issue