Merge pull request #12305 from uberbrady/fix_license_seat_reporting

Fixed: Change license_seat changing method to properly 'true up' license seats
This commit is contained in:
snipe 2023-01-04 13:22:03 -08:00 committed by GitHub
commit 818db58a7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -123,12 +123,20 @@ class License extends Depreciable
static::created(function ($license) {
$newSeatCount = $license->getAttributes()['seats'];
return static::adjustSeatCount($license, $oldSeatCount = 0, $newSeatCount);
return static::adjustSeatCount($license, 0, $newSeatCount);
});
// However, we listen for updating to be able to prevent the edit if we cannot delete enough seats.
static::updating(function ($license) {
$newSeatCount = $license->getAttributes()['seats'];
$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;
//$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;
/*
That previous method *did* mostly work, but if you ever managed to get your $license->seats value out of whack
with your actual count of license_seats *records*, you would never manage to get back 'into whack'.
The below method actually grabs a count of existing license_seats records, so it will be more accurate.
This means that if your license_seats are out of whack, you can change the quantity and hit 'save' and it
will manage to 'true up' and make your counts line up correctly.
*/
$oldSeatCount = $license->license_seats_count;
return static::adjustSeatCount($license, $oldSeatCount, $newSeatCount);
});