From aa34c4a4dd049e2d537dd63d4f1fb34f20320ec7 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Nov 2013 07:28:24 -0500 Subject: [PATCH] Add checks to prevent orphaned records --- .../admin/DepreciationsController.php | 15 +++++++++++---- app/controllers/admin/LocationsController.php | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/DepreciationsController.php b/app/controllers/admin/DepreciationsController.php index bc1842c9c8..72aee62e87 100644 --- a/app/controllers/admin/DepreciationsController.php +++ b/app/controllers/admin/DepreciationsController.php @@ -170,11 +170,18 @@ class DepreciationsController extends AdminController { return Redirect::to('admin/settings/depreciations')->with('error', Lang::get('admin/depreciations/message.not_found')); } - // Delete the depreciation - $depreciation->delete(); + if ($depreciation->has_models() > 0) { + + // Redirect to the asset management page + return Redirect::to('admin/settings/depreciations')->with('error', Lang::get('admin/depreciations/message.assoc_users')); + } else { + + $depreciation->delete(); + + // Redirect to the depreciations management page + return Redirect::to('admin/settings/depreciations')->with('success', Lang::get('admin/depreciations/message.delete.success')); + } - // Redirect to the depreciations management page - return Redirect::to('admin/settings/depreciations')->with('success', Lang::get('admin/depreciations/message.delete.success')); } diff --git a/app/controllers/admin/LocationsController.php b/app/controllers/admin/LocationsController.php index 42c202e824..a139ce4610 100644 --- a/app/controllers/admin/LocationsController.php +++ b/app/controllers/admin/LocationsController.php @@ -175,11 +175,21 @@ class LocationsController extends AdminController { return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.not_found')); } - // Delete the location - $location->delete(); - // Redirect to the locations management page - return Redirect::to('admin/settings/locations')->with('success', Lang::get('admin/locations/message.delete.success')); + if ($location->has_users() > 0) { + + // Redirect to the asset management page + return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.assoc_users')); + } else { + + $location->delete(); + + // Redirect to the locations management page + return Redirect::to('admin/settings/locations')->with('success', Lang::get('admin/locations/message.delete.success')); + } + + + }