Fix blanck string in db

This commit is contained in:
SebClem 2022-06-18 01:19:04 +02:00
parent bfcba4eb30
commit 9f1a3f737b
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
2 changed files with 39 additions and 1 deletions

View File

@ -60,7 +60,7 @@ public class GuildPreferenceEntity {
public static GuildPreferenceEntity getDefault(String guildId) { public static GuildPreferenceEntity getDefault(String guildId) {
return new GuildPreferenceEntity(guildId, false, "Welcome to this awesome server @name! ", " ", false, " ", true, false, " ", " "); return new GuildPreferenceEntity(guildId, false, "Welcome to this awesome server @name! ", null, false, null, true, false, null, null);
} }
public Integer getId() { public Integer getId() {

View File

@ -1,6 +1,8 @@
package net.Broken; package net.Broken;
import net.Broken.DB.Entity.GuildPreferenceEntity;
import net.Broken.DB.Entity.UserEntity; import net.Broken.DB.Entity.UserEntity;
import net.Broken.DB.Repository.GuildPreferenceRepository;
import net.Broken.DB.Repository.UserRepository; import net.Broken.DB.Repository.UserRepository;
import net.Broken.RestApi.ApiCommandLoader; import net.Broken.RestApi.ApiCommandLoader;
import net.Broken.Tools.Command.SlashCommandLoader; import net.Broken.Tools.Command.SlashCommandLoader;
@ -17,6 +19,7 @@ import net.dv8tion.jda.api.utils.MemberCachePolicy;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.thymeleaf.spring5.processor.SpringOptionFieldTagProcessor;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import java.util.List; import java.util.List;
@ -82,12 +85,47 @@ public class Init {
List<UserEntity> users = (List<UserEntity>) userRepository.findAll(); List<UserEntity> users = (List<UserEntity>) userRepository.findAll();
UserStatsUtils userStatsUtils = UserStatsUtils.getINSTANCE(); UserStatsUtils userStatsUtils = UserStatsUtils.getINSTANCE();
logger.debug("Stats..."); logger.debug("Stats...");
// for (UserEntity userEntity : users) { // for (UserEntity userEntity : users) {
// logger.debug("..." + userEntity.getName()); // logger.debug("..." + userEntity.getName());
// userStatsUtils.getUserStats(userEntity); // userStatsUtils.getUserStats(userEntity);
// //
// } // }
logger.debug("Guild Prefs...");
GuildPreferenceRepository guildPreference = context.getBean(GuildPreferenceRepository.class);
for(GuildPreferenceEntity pref :guildPreference.findAll()){
boolean save = false;
if(pref.getWelcomeMessage() != null && pref.getWelcomeMessage().equals(" ")){
pref.setWelcomeMessage(null);
save = true;
}
if(pref.getWelcomeChanelID() != null && pref.getWelcomeChanelID().equals(" ")){
pref.setWelcomeChanelID(null);
save = true;
}
if(pref.getWelcomeChanelID() != null && pref.getWelcomeChanelID().equals(" ")){
pref.setWelcomeChanelID(null);
save = true;
}
if(pref.getDefaultRoleId() != null && pref.getDefaultRoleId().equals(" ")){
pref.setDefaultRoleId(null);
save = true;
}
if(pref.getAutoVoiceChannelID() != null && pref.getAutoVoiceChannelID().equals(" ")){
pref.setAutoVoiceChannelID(null);
save = true;
}
if(pref.getAutoVoiceChannelTitle() != null && pref.getAutoVoiceChannelTitle().equals(" ")){
pref.setAutoVoiceChannelTitle(null);
save = true;
}
if(save){
guildPreference.save(pref);
}
}
} }
} }