Patched incorrect register dates on Nukkit

Affects issues:
- #1320
This commit is contained in:
Rsl1122 2020-02-14 15:27:44 +02:00
parent e4a7c083da
commit 6d9ef8a3db
2 changed files with 71 additions and 1 deletions

View File

@ -169,7 +169,8 @@ public abstract class SQLDB extends AbstractDatabase {
new ExtensionShowInPlayersTablePatch(),
new ExtensionTableRowValueLengthPatch(),
new CommandUsageTableRemovalPatch(),
new RegisterDateMinimizationPatch()
new RegisterDateMinimizationPatch(),
new BadNukkitRegisterValuePatch()
};
}

View File

@ -0,0 +1,69 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.storage.database.transactions.patches;
import com.djrapitops.plan.storage.database.queries.HasMoreThanZeroQueryStatement;
import com.djrapitops.plan.storage.database.sql.tables.UserInfoTable;
import com.djrapitops.plan.storage.database.sql.tables.UsersTable;
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
/**
* Patch to fix incorrect register dates for nukkit.
* https://github.com/plan-player-analytics/Plan/issues/1320
*
* @author Rsl1122
*/
public class BadNukkitRegisterValuePatch extends Patch {
@Override
public boolean hasBeenApplied() {
return !hasWrongRegisterDates();
}
public boolean hasWrongRegisterDates() {
String sql = SELECT + "COUNT(*) as c" + FROM + UserInfoTable.TABLE_NAME + WHERE + UserInfoTable.REGISTERED + "<?";
return query(new HasMoreThanZeroQueryStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setLong(1, 20000000); // Before 20th August 1970
}
});
}
@Override
protected void applyPatch() {
multiplyInTable(UserInfoTable.TABLE_NAME, UserInfoTable.REGISTERED);
multiplyInTable(UsersTable.TABLE_NAME, UsersTable.REGISTERED);
}
private void multiplyInTable(String tableName, String registered) {
String sql = "UPDATE " + tableName + " SET " +
registered + "=" + registered + "*1000" +
WHERE + registered + "<?";
execute(new ExecStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setLong(1, 20000000); // Before 20th August 1970
}
});
}
}