update for database provider specific migrations

fix issues with live radar
This commit is contained in:
RaidMax
2020-11-27 21:52:52 -06:00
parent 8ef2959f63
commit 36a02b3d7b
309 changed files with 76554 additions and 1067 deletions

View File

@ -1434,7 +1434,10 @@ namespace SharedLibraryCore.Commands
/// </summary>
public class PruneAdminsCommand : Command
{
public PruneAdminsCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
private readonly IDatabaseContextFactory _contextFactory;
public PruneAdminsCommand(CommandConfiguration config, ITranslationLookup translationLookup,
IDatabaseContextFactory contextFactory) : base(config, translationLookup)
{
Name = "prune";
Description = _translationLookup["COMMANDS_PRUNE_DESC"];
@ -1476,16 +1479,15 @@ namespace SharedLibraryCore.Commands
List<EFClient> inactiveUsers = null;
// todo: make an event for this
// update user roles
using (var context = new DatabaseContext())
{
var lastActive = DateTime.UtcNow.AddDays(-inactiveDays);
inactiveUsers = await context.Clients
.Where(c => c.Level > Permission.Flagged && c.Level <= Permission.Moderator)
.Where(c => c.LastConnection < lastActive)
.ToListAsync();
inactiveUsers.ForEach(c => c.SetLevel(Permission.User, E.Origin));
await context.SaveChangesAsync();
}
await using var context = _contextFactory.CreateContext();
var lastActive = DateTime.UtcNow.AddDays(-inactiveDays);
inactiveUsers = await context.Clients
.Where(c => c.Level > Permission.Flagged && c.Level <= Permission.Moderator)
.Where(c => c.LastConnection < lastActive)
.ToListAsync();
inactiveUsers.ForEach(c => c.SetLevel(Permission.User, E.Origin));
await context.SaveChangesAsync();
E.Origin.Tell(_translationLookup["COMMANDS_PRUNE_SUCCESS"].FormatExt(inactiveUsers.Count));
}
}