diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index ca33e3815d..b21ef96279 100644 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -202,11 +202,19 @@ class AssetsController extends AdminController { return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.not_found')); } - // Delete the asset - $asset->delete(); + if (isset($asset->assigneduser->id) && ($asset->assigneduser->id!=0)) { + // Redirect to the asset management page + return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.assoc_users')); + } else { + // Delete the asset + $asset->delete(); + + // Redirect to the asset management page + return Redirect::to('admin')->with('success', Lang::get('admin/assets/message.delete.success')); + } + + - // Redirect to the asset management page - return Redirect::to('admin')->with('success', Lang::get('admin/assets/message.delete.success')); } /** diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index 4a3d7c7148..99a7c099d6 100644 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -187,11 +187,18 @@ class LicensesController extends AdminController { return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.not_found')); } - // Delete the license - $license->delete(); + if (isset($license->assigneduser->id) && ($license->assigneduser->id!=0)) { + // Redirect to the asset management page + return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.assoc_users')); + } else { + // Delete the license + $license->delete(); + + // Redirect to the licenses management page + return Redirect::to('admin/licenses')->with('success', Lang::get('admin/licenses/message.delete.success')); + } + - // Redirect to the licenses management page - return Redirect::to('admin/licenses')->with('success', Lang::get('admin/licenses/message.delete.success')); } diff --git a/app/controllers/admin/ModelsController.php b/app/controllers/admin/ModelsController.php index 406f53d292..dcaa7f31ad 100644 --- a/app/controllers/admin/ModelsController.php +++ b/app/controllers/admin/ModelsController.php @@ -168,11 +168,20 @@ class ModelsController extends AdminController { return Redirect::to('assets/models')->with('error', Lang::get('admin/models/message.not_found')); } - // Delete the model - $model->delete(); + if ($model->assets->count() > 0) { + // Throw an error that this model is associated with assets + return Redirect::to('assets/models')->with('error', Lang::get('admin/models/message.assoc_users')); + + } else { + // Delete the model + $model->delete(); + + // Redirect to the models management page + return Redirect::to('assets/models')->with('success', Lang::get('admin/models/message.delete.success')); + } + + - // Redirect to the models management page - return Redirect::to('assets/models')->with('success', Lang::get('admin/models/message.delete.success')); } diff --git a/app/lang/en/admin/assets/message.php b/app/lang/en/admin/assets/message.php index d6164f1df0..5a0c37d686 100755 --- a/app/lang/en/admin/assets/message.php +++ b/app/lang/en/admin/assets/message.php @@ -3,6 +3,7 @@ return array( 'does_not_exist' => 'Asset does not exist.', + 'assoc_users' => 'This asset is currently checked out to a user and cannot be deleted. Please check the asset in first, and then try deleting again. ', 'create' => array( 'error' => 'Asset was not created, please try again. :(', diff --git a/app/lang/en/admin/licenses/message.php b/app/lang/en/admin/licenses/message.php index 0ba7afe8d8..943ede9494 100755 --- a/app/lang/en/admin/licenses/message.php +++ b/app/lang/en/admin/licenses/message.php @@ -4,6 +4,8 @@ return array( 'does_not_exist' => 'License does not exist.', 'user_does_not_exist' => 'User does not exist.', + 'assoc_users' => 'This license is currently checked out to a user and cannot be deleted. Please check the license in first, and then try deleting again. ', + 'create' => array( 'error' => 'License was not created, please try again.', diff --git a/app/lang/en/admin/models/message.php b/app/lang/en/admin/models/message.php index 497fd2bd12..3b87420f8e 100755 --- a/app/lang/en/admin/models/message.php +++ b/app/lang/en/admin/models/message.php @@ -3,6 +3,8 @@ return array( 'does_not_exist' => 'Model does not exist.', + 'assoc_users' => 'This model is currently associated with one or more assets and cannot be deleted. Please delete the assets, and then try deleting again. ', + 'create' => array( 'error' => 'Model was not created, please try again.', diff --git a/app/models/License.php b/app/models/License.php index 85325e3f57..e6be056409 100644 --- a/app/models/License.php +++ b/app/models/License.php @@ -30,7 +30,7 @@ class License extends Elegant { } /** - * Get action logs for this asset + * Get asset logs for this asset */ public function assetlog() { @@ -38,7 +38,7 @@ class License extends Elegant { } /** - * Get action logs for this asset + * Get admin user for this asset */ public function adminuser() {