mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-23 10:45:23 +01:00
#784 Make DataSource#purgeRecords case-insensitive
This commit is contained in:
parent
cf1032d936
commit
57f90fe410
@ -258,34 +258,7 @@ public class FlatFile implements DataSource {
|
||||
|
||||
@Override
|
||||
public void purgeRecords(Collection<String> toPurge) {
|
||||
BufferedReader br = null;
|
||||
BufferedWriter bw = null;
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
bw = new BufferedWriter(new FileWriter(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
if (args.length >= 4) {
|
||||
if (toPurge.contains(args[0])) {
|
||||
lines.add(line);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String l : lines) {
|
||||
bw.write(l + "\n");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.warning(ex.getMessage());
|
||||
return;
|
||||
} finally {
|
||||
silentClose(br);
|
||||
silentClose(bw);
|
||||
}
|
||||
throw new UnsupportedOperationException("Flat file no longer supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -698,7 +698,7 @@ public class MySQL implements DataSource {
|
||||
String sql = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
|
||||
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
for (String name : toPurge) {
|
||||
pst.setString(1, name);
|
||||
pst.setString(1, name.toLowerCase());
|
||||
pst.executeUpdate();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
|
@ -322,7 +322,7 @@ public class SQLite implements DataSource {
|
||||
String delete = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
|
||||
try (PreparedStatement deletePst = con.prepareStatement(delete)) {
|
||||
for (String name : toPurge) {
|
||||
deletePst.setString(1, name);
|
||||
deletePst.setString(1, name.toLowerCase());
|
||||
deletePst.executeUpdate();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
|
@ -369,4 +369,17 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
assertThat(dataSource.getLoggedPlayers(), empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformPurgeOperation() {
|
||||
// given
|
||||
List<String> names = Arrays.asList("Bobby", "USER", "DoesnotExist");
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
// when
|
||||
dataSource.purgeRecords(names);
|
||||
|
||||
// then
|
||||
assertThat(dataSource.getAllAuths(), empty());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user