Add checks to prevent orphaned records

This commit is contained in:
snipe
2013-11-20 07:28:24 -05:00
parent 1d04235520
commit aa34c4a4dd
2 changed files with 25 additions and 8 deletions
@@ -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'));
}
+14 -4
View File
@@ -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'));
}
}