use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class TopicsCommon method notifyUsers.
/**
* Sends a "new post" notification message to all users watching the topic.
*
* @param t The changed topic
* @param p The new message
*/
public static void notifyUsers(Topic t, Post p) {
if (SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {
TopicDAO dao = DataAccessDriver.getInstance().newTopicDAO();
List usersToNotify = dao.notifyUsers(t);
// subscribed to the topic
if (usersToNotify != null && usersToNotify.size() > 0) {
Executor.execute(new EmailSenderTask(new TopicReplySpammer(t, p, usersToNotify)));
}
}
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class ModerationAction method doSave.
public void doSave() {
String[] posts = this.request.getParameterValues("post_id");
if (posts != null) {
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
for (int i = 0; i < posts.length; i++) {
int postId = Integer.parseInt(posts[i]);
String status = this.request.getParameter("status_" + postId);
if ("defer".startsWith(status)) {
continue;
}
if ("aprove".startsWith(status)) {
Post p = DataAccessDriver.getInstance().newPostDAO().selectById(postId);
// Check is the post is in fact waiting for moderation
if (!p.isModerationNeeded()) {
continue;
}
UserDAO userDao = DataAccessDriver.getInstance().newUserDAO();
User u = userDao.selectById(p.getUserId());
boolean first = false;
Topic t = TopicRepository.getTopic(new Topic(p.getTopicId()));
if (t == null) {
t = topicDao.selectById(p.getTopicId());
if (t.getId() == 0) {
first = true;
t = topicDao.selectRaw(p.getTopicId());
}
}
DataAccessDriver.getInstance().newModerationDAO().aprovePost(postId);
boolean firstPost = (t.getFirstPostId() == postId);
if (!firstPost) {
t.setTotalReplies(t.getTotalReplies() + 1);
}
t.setLastPostId(postId);
t.setLastPostBy(u);
t.setLastPostDate(p.getTime());
t.setLastPostTime(p.getFormatedTime());
topicDao.update(t);
if (first) {
t = topicDao.selectById(t.getId());
}
TopicsCommon.updateBoardStatus(t, postId, firstPost, topicDao, DataAccessDriver.getInstance().newForumDAO());
ForumRepository.updateForumStats(t, u, p);
TopicsCommon.notifyUsers(t, p);
userDao.incrementPosts(p.getUserId());
if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
PostRepository.append(p.getTopicId(), PostCommon.preparePostForDisplay(p));
}
} else {
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
Post post = pm.selectById(postId);
if (post == null || !post.isModerationNeeded()) {
continue;
}
pm.delete(post);
new AttachmentCommon(this.request, post.getForumId()).deleteAttachments(postId, post.getForumId());
int totalPosts = topicDao.getTotalPosts(post.getTopicId());
if (totalPosts == 0) {
TopicsCommon.deleteTopic(post.getTopicId(), post.getForumId(), true);
}
}
}
}
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class TopicRepository method loadMostRecentTopics.
/**
* Add recent topics to the cache
*/
public static synchronized List loadMostRecentTopics() {
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
int limit = SystemGlobals.getIntValue(ConfigKeys.RECENT_TOPICS);
List l = tm.selectRecentTopics(limit);
cache.add(FQN, RECENT, new LinkedList(l));
return l;
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class TopicRepository method loadHottestTopics.
/**
* Add hottest topics to the cache
*/
public static synchronized List loadHottestTopics() {
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
int limit = SystemGlobals.getIntValue(ConfigKeys.HOTTEST_TOPICS);
List l = tm.selectHottestTopics(limit);
cache.add(FQN, HOTTEST, new LinkedList(l));
return l;
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class PostAction method editSave.
public void editSave() {
PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
PollDAO pollDao = DataAccessDriver.getInstance().newPollDAO();
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
Post post = postDao.selectById(this.request.getIntParameter("post_id"));
if (!PostCommon.canEditPost(post)) {
this.cannotEdit();
return;
}
boolean isModerator = SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT);
String originalMessage = post.getText();
post = PostCommon.fillPostFromRequest(post, true);
// The user wants to preview the message before posting it?
if ("1".equals(this.request.getParameter("preview"))) {
this.context.put("preview", true);
Post postPreview = new Post(post);
this.context.put("postPreview", PostCommon.preparePostForDisplay(postPreview));
this.edit(true, post);
} else {
AttachmentCommon attachments = new AttachmentCommon(this.request, post.getForumId());
try {
attachments.preProcess();
} catch (AttachmentException e) {
JForumExecutionContext.enableRollback();
post.setText(this.request.getParameter("message"));
this.context.put("errorMessage", e.getMessage());
this.context.put("post", post);
this.edit(false, post);
return;
}
Topic t = TopicRepository.getTopic(new Topic(post.getTopicId()));
if (t == null) {
t = topicDao.selectById(post.getTopicId());
}
if (!TopicsCommon.isTopicAccessible(t.getForumId())) {
return;
}
if (t.getStatus() == Topic.STATUS_LOCKED && !SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT)) {
this.topicLocked();
return;
}
postDao.update(post);
// Attachments
attachments.editAttachments(post.getId(), post.getForumId());
attachments.insertAttachments(post);
// The first message (the one which originated the topic) was changed
if (t.getFirstPostId() == post.getId()) {
t.setTitle(post.getSubject());
int newType = this.request.getIntParameter("topic_type");
boolean changeType = SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_STICKY_ANNOUNCEMENT_TOPICS) && newType != t.getType();
if (changeType) {
t.setType(newType);
}
// Poll
Poll poll = PollCommon.fillPollFromRequest();
if (poll != null && !t.isVote()) {
// They added a poll
poll.setTopicId(t.getId());
if (!this.ensurePollMinimumOptions(post, poll)) {
return;
}
pollDao.addNew(poll);
t.setVoteId(poll.getId());
} else if (poll != null) {
if (!this.ensurePollMinimumOptions(post, poll)) {
return;
}
// They edited the poll in the topic
Poll existing = pollDao.selectById(t.getVoteId());
PollChanges changes = new PollChanges(existing, poll);
if (changes.hasChanges()) {
poll.setId(existing.getId());
poll.setChanges(changes);
pollDao.update(poll);
}
} else if (t.isVote()) {
// They deleted the poll from the topic
pollDao.delete(t.getVoteId());
t.setVoteId(0);
}
topicDao.update(t);
if (changeType) {
TopicRepository.addTopic(t);
} else {
TopicRepository.updateTopic(t);
}
}
if (SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED) && isModerator && post.getUserId() != SessionFacade.getUserSession().getUserId()) {
ModerationHelper helper = new ModerationHelper();
this.request.addParameter("log_original_message", originalMessage);
ModerationLog log = helper.buildModerationLogFromRequest();
log.getPosterUser().setId(post.getUserId());
helper.saveModerationLog(log);
}
if (this.request.getParameter("notify") == null) {
topicDao.removeSubscription(post.getTopicId(), SessionFacade.getUserSession().getUserId());
}
String path = this.request.getContextPath() + "/posts/list/";
int start = ViewCommon.getStartPage();
if (start > 0) {
path += start + "/";
}
path += post.getTopicId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) + "#" + post.getId();
JForumExecutionContext.setRedirect(path);
if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
PostRepository.update(post.getTopicId(), PostCommon.preparePostForDisplay(post));
}
}
}
Aggregations