defaultMaxAge = rank.getExpireDays();
}
boolean debugEnabled = Out.isDebug(DatabaseContext.class);
for(BNLogin login : (List<BNLogin>)context.performQuery(new SelectQuery(BNLogin.class))) {
long age = login.getLastSeen().getTime();
age = System.currentTimeMillis() - age;
age /= 86400000l; // convert to days
long maxAge = defaultMaxAge;
Account account = login.getAccount();
if(account != null) {
Rank rank = account.getRank();
if(rank != null)
maxAge = rank.getExpireDays();
}
if(maxAge == 0)
continue;
if(age <= maxAge)
continue;
if(account != null)
try {
Mail.send(null, account, "Your login [ " + login.getLogin() + " ] has been removed due to inactivity (" + age + " days)");
} catch (Exception e) {
Out.exception(e);
break;
}
if(debugEnabled)
Out.debugAlways(DatabaseContext.class, "Removing " + login.getLogin() + " due to inactivity (" + age + " days)");
context.deleteObject(login);
Thread.yield();
}
try {
context.commitChanges();
} catch(Exception e) {
context.rollbackChanges();
Out.exception(e);
}
for(Account account : (List<Account>)context.performQuery(new SelectQuery(Account.class))) {
// Only consider users with no BnLogins
if(account.getBnLogins().size() != 0)
continue;
// Only consider users with positive access; banlisted users shouldn't expire