Disabled manage move h2<->mysql

Move between h2 and mysql is buggy,
see #1111 for more details
This commit is contained in:
Rsl1122 2019-07-25 11:12:39 +03:00
parent ae81afb372
commit c292d441a0
3 changed files with 27 additions and 17 deletions

View File

@ -77,27 +77,33 @@ public class ManageMoveCommand extends CommandNode {
Verify.isTrue(args.length >= 2,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 2, Arrays.toString(this.getArguments()))));
String fromDB = args[0].toLowerCase();
boolean isCorrectDB = DBType.exists(fromDB);
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, fromDB)));
DBType fromDB = DBType.getForName(args[0])
.orElseThrow(() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, args[0])));
String toDB = args[1].toLowerCase();
isCorrectDB = DBType.exists(toDB);
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, toDB)));
DBType toDB = DBType.getForName(args[1])
.orElseThrow(() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, args[1])));
Verify.isFalse(fromDB.equalsIgnoreCase(toDB),
Verify.isFalse(fromDB == toDB,
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
if (!Verify.contains("-a", args)) {
sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_OVERWRITE, toDB)));
sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_OVERWRITE, toDB.getConfigName())));
return;
}
// Temporarily disabled due to issues
boolean transferH2 = fromDB == DBType.H2 || toDB == DBType.H2;
boolean transferMySQL = fromDB == DBType.MYSQL || toDB == DBType.MYSQL;
if (transferH2 && transferMySQL) {
sender.sendMessage("§cDirect transfers between H2 and MySQL are temporarily disabled due to a bug: See the issue link for workaround");
sender.sendLink("Link to Github Issue", "https://github.com/plan-player-analytics/Plan/issues/1111");
return;
}
try {
final Database fromDatabase = dbSystem.getActiveDatabaseByName(fromDB);
final Database toDatabase = dbSystem.getActiveDatabaseByName(toDB);
final Database fromDatabase = dbSystem.getActiveDatabaseByType(fromDB);
final Database toDatabase = dbSystem.getActiveDatabaseByType(toDB);
fromDatabase.init();
toDatabase.init();

View File

@ -81,7 +81,6 @@ public enum DBType {
return Optional.of(dbType);
}
}
return Optional.empty();
}

View File

@ -18,6 +18,7 @@ package com.djrapitops.plan.system.database;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.H2DB;
import com.djrapitops.plan.db.SQLiteDB;
@ -27,7 +28,6 @@ import com.djrapitops.plan.system.locale.lang.PluginLang;
import com.djrapitops.plugin.benchmarking.Timings;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Singleton;
import java.util.HashSet;
@ -69,13 +69,18 @@ public abstract class DBSystem implements SubSystem {
}
public Database getActiveDatabaseByName(String dbName) {
return DBType.getForName(dbName)
.map(this::getActiveDatabaseByType)
.orElseThrow(() -> new IllegalArgumentException(locale.getString(PluginLang.ENABLE_FAIL_WRONG_DB, dbName)));
}
public Database getActiveDatabaseByType(DBType type) {
for (Database database : getDatabases()) {
String dbConfigName = database.getType().getConfigName();
if (Verify.equalsIgnoreCase(dbName, dbConfigName)) {
if (database.getType() == type) {
return database;
}
}
throw new IllegalArgumentException(locale.getString(PluginLang.ENABLE_FAIL_WRONG_DB, dbName));
throw new IllegalArgumentException(locale.getString(PluginLang.ENABLE_FAIL_WRONG_DB, type != null ? type.getName() : "null"));
}
public Set<Database> getDatabases() {