private void migrateMessages(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
if (!uhd.getBooleanDataValue(TASK_MIGRATE_FORUMS_MESSAGES)) {
log.audit("+-----------------------------------------------------------------------------+");
log.audit("+... Calcualating word and character count in existing forum posts ...+");
log.audit("+-----------------------------------------------------------------------------+");
TextService languageService = new TextServiceImpl();
int counter = 0;
ForumManager fMgr = ForumManager.getInstance();
List<Long> allForumKeys = fMgr.getAllForumKeys();
if (log.isDebug()) log.info("Found " + allForumKeys.size() + " forums to migrate.");
for(Long forumKey:allForumKeys) {
List<Message> allMessages = fMgr.getMessagesByForumID(forumKey);
for (Message message : allMessages) {
try{
String body = message.getBody();
Locale locale = languageService.detectLocale(body);
int characters = languageService.characterCount(body, locale);
message.setNumOfCharacters(characters);
int words = languageService.wordCount(body, locale);
message.setNumOfWords(words);
counter++;
DBFactory.getInstance().updateObject(message);