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
43 public class VerifyMessageBoards extends VerifyProcess {
44
45 public void verify() throws VerifyException {
46 _log.info("Verifying");
47
48 try {
49 verifyMessageBoards();
50 }
51 catch (Exception e) {
52 throw new VerifyException(e);
53 }
54 }
55
56 protected void verifyMessageBoards() throws Exception {
57 List<MBCategory> categories =
58 MBCategoryLocalServiceUtil.getMBCategories(
59 QueryUtil.ALL_POS, QueryUtil.ALL_POS);
60
61 if (_log.isDebugEnabled()) {
62 _log.debug(
63 "Processing " + categories.size() +
64 " categories for statistics accuracy");
65 }
66
67 for (MBCategory category : categories) {
68 int threadCount = MBThreadLocalServiceUtil.getCategoryThreadsCount(
69 category.getCategoryId());
70 int messageCount =
71 MBMessageLocalServiceUtil.getCategoryMessagesCount(
72 category.getCategoryId());
73
74 if ((category.getThreadCount() != threadCount) ||
75 (category.getMessageCount() != messageCount)) {
76
77 category.setThreadCount(threadCount);
78 category.setMessageCount(messageCount);
79
80 MBCategoryLocalServiceUtil.updateMBCategory(category);
81 }
82 }
83
84 if (_log.isDebugEnabled()) {
85 _log.debug("Statistics verified for categories");
86 }
87
88 List<MBThread> threads = MBThreadLocalServiceUtil.getMBThreads(
89 QueryUtil.ALL_POS, QueryUtil.ALL_POS);
90
91 if (_log.isDebugEnabled()) {
92 _log.debug(
93 "Processing " + threads.size() +
94 " threads for statistics accuracy");
95 }
96
97 for (MBThread thread : threads) {
98 int messageCount = MBMessageLocalServiceUtil.getThreadMessagesCount(
99 thread.getThreadId());
100
101 if (thread.getMessageCount() != messageCount) {
102 thread.setMessageCount(messageCount);
103
104 MBThreadLocalServiceUtil.updateMBThread(thread);
105 }
106 }
107
108 if (_log.isDebugEnabled()) {
109 _log.debug("Statistics verified for threads");
110 }
111
112 List<MBMessage> messages =
113 MBMessageLocalServiceUtil.getNoAssetMessages();
114
115 if (_log.isDebugEnabled()) {
116 _log.debug(
117 "Processing " + messages.size() +
118 " messages with no tags assets");
119 }
120
121 for (MBMessage message : messages) {
122 try {
123 MBMessageLocalServiceUtil.updateTagsAsset(
124 message.getUserId(), message, new String[0]);
125 }
126 catch (Exception e) {
127 if (_log.isWarnEnabled()) {
128 _log.warn(
129 "Unable to update tags asset for message " +
130 message.getMessageId() + ": " + e.getMessage());
131 }
132 }
133 }
134
135 if (_log.isDebugEnabled()) {
136 _log.debug("Tags assets verified for messages");
137 }
138 }
139
140 private static Log _log = LogFactoryUtil.getLog(VerifyMessageBoards.class);
141
142 }