Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public void onEnable() {
try {
plotSquared.setConfigurationVersion("v5");
} catch (final Exception e) {
e.printStackTrace();
LOGGER.error("Failed to update configuration version", e);
}
}
}
Expand Down
31 changes: 18 additions & 13 deletions Core/src/main/java/com/plotsquared/core/database/SQLManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,18 @@ public void setSQL(PreparedStatement stmt, Integer obj) throws SQLException {
@Override
public boolean convertFlags() {
final Map<Integer, Map<String, String>> flagMap = new HashMap<>();
try {
// only migrate flags, if plot_settings table has flags column
DatabaseMetaData metaData = this.connection.getMetaData();
try (ResultSet rs = metaData.getColumns(null, null, this.prefix + "plot_settings", "flags")) {
if (!rs.next()) {
return true;
}
}
} catch (SQLException e) {
LOGGER.error("Failed to query table metadata", e);
return false;
}
try (Statement statement = this.connection.createStatement()) {
try (ResultSet resultSet = statement
.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) {
Expand All @@ -1742,11 +1754,10 @@ public boolean convertFlags() {
if (element.contains(":")) {
String[] split = element.split(":"); // splits flag:value
try {
String flag_str =
split[1].replaceAll("¯", ":").replaceAll("\u00B4", ",");
String flag_str = split[1].replace("¯", ":").replace("´", ",");
flagMap.get(id).put(split[0], flag_str);
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("Failed to migrate flag value", e);
}
}
}
Expand All @@ -1759,8 +1770,7 @@ public boolean convertFlags() {
LOGGER.info("Loaded {} plot flag collections...", flagMap.size());
LOGGER.info("Attempting to store these flags in the new table...");
try (final PreparedStatement preparedStatement = this.connection.prepareStatement(
"INSERT INTO `" + SQLManager.this.prefix
+ "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) {
"INSERT INTO `" + this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) {

long timeStarted = System.currentTimeMillis();
int flagsProcessed = 0;
Expand All @@ -1785,23 +1795,18 @@ public boolean convertFlags() {
try {
preparedStatement.executeBatch();
} catch (final Exception e) {
LOGGER.error("Failed to store flag values for plot with entry ID: {}", plotFlagEntry.getKey());
e.printStackTrace();
LOGGER.error("Failed to store flag values for plot with entry ID: {}", plotFlagEntry.getKey(), e);
continue;
}

if (System.currentTimeMillis() - timeStarted >= 1000L || plotsProcessed >= flagMap
.size()) {
if (System.currentTimeMillis() - timeStarted >= 1000L || plotsProcessed >= flagMap.size()) {
timeStarted = System.currentTimeMillis();
LOGGER.info(
"... Flag conversion in progress. {}% done",
String.format("%.1f", ((float) flagsProcessed / totalFlags) * 100)
);
}
LOGGER.info(
"- Finished converting flags for plot with entry ID: {}",
plotFlagEntry.getKey()
);
LOGGER.info("- Finished converting flags for plot with entry ID: {}", plotFlagEntry.getKey());
}
} catch (final Exception e) {
LOGGER.error("Failed to store flag values", e);
Expand Down
Loading