From 9f1a3f737b3d429b986060bcc0e280eb5ce97a2e Mon Sep 17 00:00:00 2001 From: SebClem Date: Sat, 18 Jun 2022 01:19:04 +0200 Subject: [PATCH] Fix blanck string in db --- .../DB/Entity/GuildPreferenceEntity.java | 2 +- src/main/java/net/Broken/Init.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/Broken/DB/Entity/GuildPreferenceEntity.java b/src/main/java/net/Broken/DB/Entity/GuildPreferenceEntity.java index f13ab11..5af4ab3 100644 --- a/src/main/java/net/Broken/DB/Entity/GuildPreferenceEntity.java +++ b/src/main/java/net/Broken/DB/Entity/GuildPreferenceEntity.java @@ -60,7 +60,7 @@ public class GuildPreferenceEntity { 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() { diff --git a/src/main/java/net/Broken/Init.java b/src/main/java/net/Broken/Init.java index a773e04..e8f0186 100644 --- a/src/main/java/net/Broken/Init.java +++ b/src/main/java/net/Broken/Init.java @@ -1,6 +1,8 @@ package net.Broken; +import net.Broken.DB.Entity.GuildPreferenceEntity; import net.Broken.DB.Entity.UserEntity; +import net.Broken.DB.Repository.GuildPreferenceRepository; import net.Broken.DB.Repository.UserRepository; import net.Broken.RestApi.ApiCommandLoader; 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.Logger; import org.springframework.context.ApplicationContext; +import org.thymeleaf.spring5.processor.SpringOptionFieldTagProcessor; import javax.security.auth.login.LoginException; import java.util.List; @@ -82,12 +85,47 @@ public class Init { List users = (List) userRepository.findAll(); UserStatsUtils userStatsUtils = UserStatsUtils.getINSTANCE(); logger.debug("Stats..."); + // for (UserEntity userEntity : users) { // logger.debug("..." + userEntity.getName()); // 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); + } + } + } }