#886 Do not include players with lastlogin = 0 in autopurge or default purge
This commit is contained in:
@@ -138,8 +138,8 @@ public class CacheDataSource implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRecordsToPurge(long until) {
|
||||
return source.getRecordsToPurge(until);
|
||||
public Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero) {
|
||||
return source.getRecordsToPurge(until, includeEntriesWithLastLoginZero);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,9 +74,11 @@ 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/Xephi/AuthMeReloaded/issues/886">issue #886</a>
|
||||
* @return The account names selected to purge
|
||||
*/
|
||||
Set<String> getRecordsToPurge(long until);
|
||||
Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero);
|
||||
|
||||
/**
|
||||
* Purge the given players from the database.
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -211,30 +210,8 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRecordsToPurge(long until) {
|
||||
BufferedReader br = null;
|
||||
Set<String> list = new HashSet<>();
|
||||
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
if (args.length >= 4) {
|
||||
if (Long.parseLong(args[3]) >= until) {
|
||||
list.add(args[0]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.warning(ex.getMessage());
|
||||
return list;
|
||||
} finally {
|
||||
silentClose(br);
|
||||
}
|
||||
|
||||
return list;
|
||||
public Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero) {
|
||||
throw new UnsupportedOperationException("Flat file no longer supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -572,10 +572,13 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRecordsToPurge(long until) {
|
||||
public Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero) {
|
||||
Set<String> list = new HashSet<>();
|
||||
|
||||
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
|
||||
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + " < ?";
|
||||
if (!includeEntriesWithLastLoginZero) {
|
||||
select += " AND " + col.LAST_LOGIN + " <> 0";
|
||||
}
|
||||
try (Connection con = getConnection();
|
||||
PreparedStatement selectPst = con.prepareStatement(select)) {
|
||||
selectPst.setLong(1, until);
|
||||
|
||||
@@ -299,10 +299,13 @@ public class SQLite implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRecordsToPurge(long until) {
|
||||
public Set<String> getRecordsToPurge(long until, boolean includeEntriesWithLastLoginZero) {
|
||||
Set<String> list = new HashSet<>();
|
||||
|
||||
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
|
||||
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + " < ?";
|
||||
if (!includeEntriesWithLastLoginZero) {
|
||||
select += " AND " + col.LAST_LOGIN + " <> 0";
|
||||
}
|
||||
try (PreparedStatement selectPst = con.prepareStatement(select)) {
|
||||
selectPst.setLong(1, until);
|
||||
try (ResultSet rs = selectPst.executeQuery()) {
|
||||
|
||||
Reference in New Issue
Block a user