練功房推薦書單

  • 猛虎出柙雙劍合璧版--最新 OCA / OCP Java SE 7 Programmer 專業認證 (電子書)
  • 流浪教師存零股存到3000萬(全新增修版)(書+DVD)
  • 開始在關西自助旅行(京都‧大阪‧神戶‧奈良)(全新增訂版)
  • 不敗教主的300張股票存股術

Making post from another application RSS feed
討論區首頁 » JForum中文社群 JForum Chinese Users Community
發表人 內容
jforumrookie

十級學員

註冊時間: 2011/9/28
文章: 2
離線
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

七段學員
[Avatar]

註冊時間: 2007/1/2
文章: 711
來自: 台北
離線
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.

分享經驗 累積智慧
[WWW]
jforumrookie

十級學員

註冊時間: 2011/9/28
文章: 2
離線
Thanks. Will give it a try.
 
討論區首頁 » JForum中文社群 JForum Chinese Users Community
前往:   
行動版