Merge pull request #161 from Moonlight-Panel/FixServerDelete
Fixed server delete
This commit is contained in:
@@ -19,6 +19,7 @@ namespace Moonlight.App.Services;
|
|||||||
|
|
||||||
public class ServerService
|
public class ServerService
|
||||||
{
|
{
|
||||||
|
private readonly Repository<ServerVariable> ServerVariablesRepository;
|
||||||
private readonly ServerRepository ServerRepository;
|
private readonly ServerRepository ServerRepository;
|
||||||
private readonly UserRepository UserRepository;
|
private readonly UserRepository UserRepository;
|
||||||
private readonly ImageRepository ImageRepository;
|
private readonly ImageRepository ImageRepository;
|
||||||
@@ -50,7 +51,8 @@ public class ServerService
|
|||||||
NodeService nodeService,
|
NodeService nodeService,
|
||||||
NodeAllocationRepository nodeAllocationRepository,
|
NodeAllocationRepository nodeAllocationRepository,
|
||||||
DateTimeService dateTimeService,
|
DateTimeService dateTimeService,
|
||||||
EventSystem eventSystem)
|
EventSystem eventSystem,
|
||||||
|
Repository<ServerVariable> serverVariablesRepository)
|
||||||
{
|
{
|
||||||
ServerRepository = serverRepository;
|
ServerRepository = serverRepository;
|
||||||
WingsApiHelper = wingsApiHelper;
|
WingsApiHelper = wingsApiHelper;
|
||||||
@@ -67,6 +69,7 @@ public class ServerService
|
|||||||
NodeAllocationRepository = nodeAllocationRepository;
|
NodeAllocationRepository = nodeAllocationRepository;
|
||||||
DateTimeService = dateTimeService;
|
DateTimeService = dateTimeService;
|
||||||
Event = eventSystem;
|
Event = eventSystem;
|
||||||
|
ServerVariablesRepository = serverVariablesRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Server EnsureNodeData(Server s)
|
private Server EnsureNodeData(Server s)
|
||||||
@@ -401,17 +404,13 @@ public class ServerService
|
|||||||
|
|
||||||
public async Task Delete(Server s)
|
public async Task Delete(Server s)
|
||||||
{
|
{
|
||||||
throw new DisplayException("Deleting a server is currently a bit buggy. So its disabled for your safety");
|
var backups = await GetBackups(s);
|
||||||
|
|
||||||
var server = EnsureNodeData(s);
|
|
||||||
|
|
||||||
var backups = await GetBackups(server);
|
|
||||||
|
|
||||||
foreach (var backup in backups)
|
foreach (var backup in backups)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await DeleteBackup(server, backup);
|
await DeleteBackup(s, backup);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -419,17 +418,25 @@ public class ServerService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var server = ServerRepository
|
||||||
|
.Get()
|
||||||
|
.Include(x => x.Variables)
|
||||||
|
.Include(x => x.Node)
|
||||||
|
.First(x => x.Id == s.Id);
|
||||||
|
|
||||||
await WingsApiHelper.Delete(server.Node, $"api/servers/{server.Uuid}", null);
|
await WingsApiHelper.Delete(server.Node, $"api/servers/{server.Uuid}", null);
|
||||||
|
|
||||||
//TODO: Fix empty data models
|
foreach (var variable in server.Variables.ToArray())
|
||||||
|
{
|
||||||
|
ServerVariablesRepository.Delete(variable);
|
||||||
|
}
|
||||||
|
|
||||||
server.Allocations = new();
|
server.Allocations = new();
|
||||||
server.MainAllocation = null;
|
server.MainAllocation = null;
|
||||||
server.Variables = new();
|
server.Variables = new();
|
||||||
server.Backups = new();
|
server.Backups = new();
|
||||||
|
|
||||||
ServerRepository.Update(server);
|
ServerRepository.Update(server);
|
||||||
|
|
||||||
ServerRepository.Delete(server);
|
ServerRepository.Delete(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user