1
14
15 package com.liferay.portal.verify;
16
17 import com.liferay.portal.kernel.dao.orm.QueryUtil;
18 import com.liferay.portal.kernel.log.Log;
19 import com.liferay.portal.kernel.log.LogFactoryUtil;
20 import com.liferay.portlet.messageboards.model.MBCategory;
21 import com.liferay.portlet.messageboards.model.MBMessage;
22 import com.liferay.portlet.messageboards.model.MBThread;
23 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
24 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
25 import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
26
27 import java.util.List;
28
29
34 public class VerifyMessageBoards extends VerifyProcess {
35
36 protected void doVerify() throws Exception {
37 List<MBCategory> categories =
38 MBCategoryLocalServiceUtil.getMBCategories(
39 QueryUtil.ALL_POS, QueryUtil.ALL_POS);
40
41 if (_log.isDebugEnabled()) {
42 _log.debug(
43 "Processing " + categories.size() +
44 " categories for statistics accuracy");
45 }
46
47 for (MBCategory category : categories) {
48 int threadCount = MBThreadLocalServiceUtil.getCategoryThreadsCount(
49 category.getCategoryId());
50 int messageCount =
51 MBMessageLocalServiceUtil.getCategoryMessagesCount(
52 category.getCategoryId());
53
54 if ((category.getThreadCount() != threadCount) ||
55 (category.getMessageCount() != messageCount)) {
56
57 category.setThreadCount(threadCount);
58 category.setMessageCount(messageCount);
59
60 MBCategoryLocalServiceUtil.updateMBCategory(category);
61 }
62 }
63
64 if (_log.isDebugEnabled()) {
65 _log.debug("Statistics verified for categories");
66 }
67
68 List<MBThread> threads = MBThreadLocalServiceUtil.getMBThreads(
69 QueryUtil.ALL_POS, QueryUtil.ALL_POS);
70
71 if (_log.isDebugEnabled()) {
72 _log.debug(
73 "Processing " + threads.size() +
74 " threads for statistics accuracy");
75 }
76
77 for (MBThread thread : threads) {
78 int messageCount = MBMessageLocalServiceUtil.getThreadMessagesCount(
79 thread.getThreadId());
80
81 if (thread.getMessageCount() != messageCount) {
82 thread.setMessageCount(messageCount);
83
84 MBThreadLocalServiceUtil.updateMBThread(thread);
85 }
86 }
87
88 if (_log.isDebugEnabled()) {
89 _log.debug("Statistics verified for threads");
90 }
91
92 List<MBMessage> messages =
93 MBMessageLocalServiceUtil.getNoAssetMessages();
94
95 if (_log.isDebugEnabled()) {
96 _log.debug(
97 "Processing " + messages.size() +
98 " messages with no tags assets");
99 }
100
101 for (MBMessage message : messages) {
102 try {
103 MBMessageLocalServiceUtil.updateTagsAsset(
104 message.getUserId(), message, new String[0]);
105 }
106 catch (Exception e) {
107 if (_log.isWarnEnabled()) {
108 _log.warn(
109 "Unable to update tags asset for message " +
110 message.getMessageId() + ": " + e.getMessage());
111 }
112 }
113 }
114
115 if (_log.isDebugEnabled()) {
116 _log.debug("Tags assets verified for messages");
117 }
118 }
119
120 private static Log _log = LogFactoryUtil.getLog(VerifyMessageBoards.class);
121
122 }