會員註冊 / 登入  |  電腦版  |  Jump to bottom of page

JForum中文社群 JForum Chinese Users Community » Making post from another application

發表人: jforumrookie, 十級學員
2011-09-28 05:13:19
Hi,

I'm new to jforum. Does anyone know what is the best way to make a post from another web application? We have an existing web application that when a user post a message to the application, we want to make a post to our jforum without the user having to make a post twice. Does anyone have any suggestion? I tried to manually insert a record into the jforum_posts, jforum_posts_text, and jforum_topics table, but the post does not show up on jforum.

Thanks.

發表人: andowson, 七段學員
2011-09-28 07:52:22
I don't have any experience on this kind of application. Here are some hints, you can try them yourself.
1.You may reference the net.jforum.view.install.InstallAction.java's saveMessage() method:

private void saveMessage(final Connection conn, final String subject, final String message, final int topicType, final int forumId, final int userId, final String sourceIp)
{
try {
ConfigLoader.createLoginAuthenticator();
ConfigLoader.loadDaoImplementation();
SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC));
SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER));

final JForumExecutionContext executionContext = JForumExecutionContext.get();
executionContext.setConnection(conn);
JForumExecutionContext.set(executionContext);

final User user = new User(userId);

// Create topic
final Topic topic = new Topic();
topic.setPostedBy(user);
topic.setTitle(subject);
topic.setTime(new Date());
topic.setType(topicType);
topic.setForumId(forumId);

final TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
topicDao.addNew(topic);

// Create post
final Post post = new Post();
post.setSubject(topic.getTitle());
post.setTime(topic.getTime());
post.setUserId(user.getId());
post.setText(message);
post.setForumId(topic.getForumId());
post.setSmiliesEnabled(true);
post.setHtmlEnabled(true);
post.setBbCodeEnabled(true);
post.setUserIp(sourceIp);
post.setTopicId(topic.getId());

final PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
postDao.addNew(post);

// Update topic
topic.setFirstPostId(post.getId());
topic.setLastPostId(post.getId());

topicDao.update(topic);
DataAccessDriver.getInstance().newUserDAO().incrementPosts(post.getUserId());

// Update forum stats
final ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
forumDao.incrementTotalTopics(forumId, 1);
forumDao.setLastPost(forumId, post.getId());
}
finally {
final JForumExecutionContext executionContext = JForumExecutionContext.get();
executionContext.setConnection(null);
JForumExecutionContext.set(executionContext);
}
}


2.You may reference the net.jforum.api.integration.mail.pop.POPPostAction.java's insertMessages() method.

發表人: jforumrookie, 十級學員
2011-09-29 01:11:29
Thanks. Will give it a try.




會員註冊 / 登入  |  電腦版  |  Jump to top of page