From a64e4c95782faebdfdeada682d09ef70b6cad99c Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 18 Oct 2014 11:24:18 -0700 Subject: [PATCH] *console commands Added plot purge --- .../plot/database/DBFunc.java | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 5d8710cb9..523cdaba9 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -630,7 +630,60 @@ public class DBFunc { } public static void purge(final String world) { - // TODO purge + runTask(new Runnable() { + @Override + public void run() { + ArrayList ids = new ArrayList(); + try { + PreparedStatement stmt = connection.prepareStatement("SELECT `id`, FROM `plot` WHERE `world` = ?"); + stmt.setString(1, world); + ResultSet result = stmt.executeQuery(); + while (result.next()) { + int id = result.getInt("id"); + ids.add(id); + } + } + catch (SQLException e) { + e.printStackTrace(); + Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '"+world+"'!"); + return; + } + + try { + + String prefix = ""; + StringBuilder idstr = new StringBuilder(""); + + for (Integer id:ids) { + idstr.append(prefix + id); + prefix = " OR `plot_plot_id` = "; + } + + PreparedStatement stmt = connection.prepareStatement("DELETE FROM `plot_helpers` WHERE `plot_plot_id` = "+idstr+""); + stmt.executeUpdate(); + stmt.close(); + + stmt = connection.prepareStatement("DELETE FROM `plot_denied` WHERE `plot_plot_id` = "+idstr+""); + stmt.executeUpdate(); + stmt.close(); + + stmt = connection.prepareStatement("DELETE FROM `plot_settings` WHERE `plot_plot_id` = "+idstr+""); + stmt.executeUpdate(); + stmt.close(); + + stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `world` = ?"); + stmt.setString(1, world); + stmt.executeUpdate(); + stmt.close(); + } + catch (SQLException e) { + e.printStackTrace(); + Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '"+world+"'!"); + return; + } + Logger.add(LogLevel.GENERAL, "SUCCESSFULLY PURGED WORLD '"+world+"'!"); + } + }); } /**