Clean up orphaned non-global admins on the expire timer

This commit is contained in:
Ravid-A 2026-05-31 17:47:13 +03:00
parent e028441b56
commit fd94ac8d2b
5 changed files with 29 additions and 1 deletions

View file

@ -677,4 +677,24 @@ public class PermissionManager(IDatabaseProvider? databaseProvider)
CS2_SimpleAdmin._logger?.LogCritical("Unable to remove expired admins");
}
}
/// <summary>
/// Deletes orphaned admins that are not global and have no server assignments left.
/// </summary>
public async Task DeleteOrphanedAdmins()
{
if (databaseProvider == null) return;
try
{
await using var connection = await databaseProvider.CreateConnectionAsync();
var sql = databaseProvider.GetDeleteOrphanedAdminsQuery();
await connection.ExecuteAsync(sql);
}
catch (Exception)
{
CS2_SimpleAdmin._logger?.LogCritical("Unable to remove orphaned admins");
}
}
}