Search in sources :

Example 1 with PollChanges

use of net.jforum.entities.PollChanges 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));
        }
    }
}
Also used : Post(net.jforum.entities.Post) ModerationLog(net.jforum.entities.ModerationLog) TopicDAO(net.jforum.dao.TopicDAO) AttachmentException(net.jforum.exceptions.AttachmentException) PollDAO(net.jforum.dao.PollDAO) PostDAO(net.jforum.dao.PostDAO) PollChanges(net.jforum.entities.PollChanges) Poll(net.jforum.entities.Poll) Topic(net.jforum.entities.Topic) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Aggregations

PollDAO (net.jforum.dao.PollDAO)1 PostDAO (net.jforum.dao.PostDAO)1 TopicDAO (net.jforum.dao.TopicDAO)1 ModerationLog (net.jforum.entities.ModerationLog)1 Poll (net.jforum.entities.Poll)1 PollChanges (net.jforum.entities.PollChanges)1 Post (net.jforum.entities.Post)1 Topic (net.jforum.entities.Topic)1 AttachmentException (net.jforum.exceptions.AttachmentException)1 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)1