#792 Include registration date into purging logic

- Take MAX(reg_date, login_date) as timestamp to compare against
- Remove the second "all" parameter to include entries with 0 registration date -> we expect registration date to always be set to the current date, so the parameter becomes obsolete
This commit is contained in:
ljacqu
2017-10-15 18:29:01 +02:00
parent 1df5308e56
commit ea58e20c3d
12 changed files with 50 additions and 93 deletions
@@ -137,8 +137,8 @@ public class CacheDataSource implements DataSource {
}
@Override
public Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero) {
return source.getRecordsToPurge(until, includeEntriesWithLastLoginZero);
public Set<String> getRecordsToPurge(long until) {
return source.getRecordsToPurge(until);
}
@Override
@@ -74,11 +74,9 @@ public interface DataSource extends Reloadable {
* Get all records in the database whose last login was before the given time.
*
* @param until The minimum last login
* @param includeEntriesWithLastLoginZero Whether entries with lastlogin = 0 should be included or not,
* see <a href="https://github.com/AuthMe/AuthMeReloaded/issues/886">issue #886</a>
* @return The account names selected to purge
*/
Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero);
Set<String> getRecordsToPurge(long until);
/**
* Purge the given players from the database.
@@ -189,7 +189,7 @@ public class FlatFile implements DataSource {
}
@Override
public Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero) {
public Set<String> getRecordsToPurge(long until) {
throw new UnsupportedOperationException("Flat file no longer supported");
}
@@ -407,12 +407,12 @@ public class MySQL implements DataSource {
}
@Override
public Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero) {
public Set<String> getRecordsToPurge(long until) {
Set<String> list = new HashSet<>();
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + " < ?";
if (!includeEntriesWithLastLoginZero) {
select += " AND " + col.LAST_LOGIN + " <> 0";
}
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE GREATEST("
+ " COALESCE(" + col.LAST_LOGIN + ", 0),"
+ " COALESCE(" + col.REGISTRATION_DATE + ", 0)"
+ ") < ?;";
try (Connection con = getConnection();
PreparedStatement selectPst = con.prepareStatement(select)) {
selectPst.setLong(1, until);
@@ -308,12 +308,12 @@ public class SQLite implements DataSource {
}
@Override
public Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero) {
public Set<String> getRecordsToPurge(long until) {
Set<String> list = new HashSet<>();
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + " < ?";
if (!includeEntriesWithLastLoginZero) {
select += " AND " + col.LAST_LOGIN + " <> 0";
}
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE MAX("
+ " COALESCE(" + col.LAST_LOGIN + ", 0),"
+ " COALESCE(" + col.REGISTRATION_DATE + ", 0)"
+ ") < ?;";
try (PreparedStatement selectPst = con.prepareStatement(select)) {
selectPst.setLong(1, until);
try (ResultSet rs = selectPst.executeQuery()) {
@@ -76,7 +76,7 @@ public class RakamakConverter implements Converter {
for (Entry<String, HashedPassword> m : playerPassword.entrySet()) {
String playerName = m.getKey();
HashedPassword psw = playerPassword.get(playerName);
String ip = useIp ? playerIp.get(playerName) : "127.0.0.1";
String ip = playerIp.get(playerName);
PlayerAuth auth = PlayerAuth.builder()
.name(playerName)
.realName(playerName)
@@ -86,7 +86,7 @@ public class RakamakConverter implements Converter {
database.saveAuth(auth);
database.updateSession(auth);
}
Utils.logAndSendMessage(sender, "Rakamak database has been imported correctly");
Utils.logAndSendMessage(sender, "Rakamak database has been imported successfully");
} catch (IOException ex) {
ConsoleLogger.logException("Can't open the rakamak database file! Does it exist?", ex);
}