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