forked from Alex/Pterodactyl-Panel
Implement node deletion properly, fixes #173
This commit is contained in:
parent
0e89ecb427
commit
723b608e0c
@ -253,20 +253,22 @@ class NodesController extends Controller
|
||||
|
||||
public function deleteNode(Request $request, $id)
|
||||
{
|
||||
$node = Models\Node::findOrFail($id);
|
||||
$servers = Models\Server::where('node', $id)->count();
|
||||
if ($servers > 0) {
|
||||
Alert::danger('You cannot delete a node with servers currently attached to it.')->flash();
|
||||
return redirect()->route('admin.nodes.view', [
|
||||
'id' => $id,
|
||||
'tab' => 'tab_delete'
|
||||
]);
|
||||
try {
|
||||
$repo = new NodeRepository;
|
||||
$repo->delete($id);
|
||||
Alert::success('Successfully deleted the requested node from the panel.')->flash();
|
||||
return redirect()->route('admin.nodes');
|
||||
} catch (DisplayException $e) {
|
||||
Alert::danger($e->getMessage())->flash();
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
Alert::danger('An unhandled exception occured while attempting to delete this node. Please try again.')->flash();
|
||||
}
|
||||
|
||||
$node->delete();
|
||||
Alert::success('Node successfully deleted.')->flash();
|
||||
return redirect()->route('admin.nodes');
|
||||
|
||||
return redirect()->route('admin.nodes.view', [
|
||||
'id' => $id,
|
||||
'tab' => 'tab_delete'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user