From 012a889444fa25b174a5fb2c67e89c8c5fcf09aa Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 27 Nov 2013 14:13:29 -0500 Subject: [PATCH] Corrected license seat count associated with license. Fixes #75 --- app/controllers/admin/LicensesController.php | 14 ++++++++++---- app/models/LicenseSeat.php | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index c6dcd6f453ef..8e1bdfb76f2c 100644 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -201,17 +201,23 @@ public function getDelete($licenseId) // Check if the license exists if (is_null($license = License::find($licenseId))) { - // Redirect to the blogs management page + // Redirect to the license management page return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.not_found')); } - if (count($license->assignedusers) > 0) { - // Redirect to the asset management page + if (($license->assignedcount()) && ($license->assignedcount() > 0)) { + + // Redirect to the license management page return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.assoc_users')); + } else { - // Delete the license + + // Delete the license and the associated license seats + $licenseseats = $license->licenseseats(); + $licenseseats->delete(); $license->delete(); + // Redirect to the licenses management page return Redirect::to('admin/licenses')->with('success', Lang::get('admin/licenses/message.delete.success')); } diff --git a/app/models/LicenseSeat.php b/app/models/LicenseSeat.php index ae0ce4441304..3fe22b7f9879 100644 --- a/app/models/LicenseSeat.php +++ b/app/models/LicenseSeat.php @@ -2,6 +2,7 @@ class LicenseSeat extends Elegant { protected $table = 'license_seats'; + protected $softDelete = true; public function license() {