Implement node deletion properly, fixes #173

This commit is contained in:
Dane Everitt 2016-11-26 16:29:13 -05:00
parent 0e89ecb427
commit 723b608e0c
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 38 additions and 14 deletions

View file

@ -229,8 +229,30 @@ class NodeRepository {
public function delete($id)
{
// @TODO: add logic;
return true;
$node = Models\Node::findOrFail($id);
if (Models\Server::where('node', $id)->count() > 0) {
throw new DisplayException('You cannot delete a node with servers currently attached to it.');
}
DB::beginTransaction();
try {
// Unlink Database Servers
Models\DatabaseServer::where('linked_node', $node->id)->update([
'linked_node' => null,
]);
// Delete Allocations
Models\Allocation::where('node', $node->id)->delete();
// Delete Node
$node->delete();
DB::commit();
} catch (\Exception $ex) {
DB::rollback();
throw $ex;
}
}
}