posted 16 years ago
Thank you a lot for the reply,
i have solved in another way i don't now if is much clean but work much well!"
So i have used the same method that is used in Jforum to delete and update statistics, and i have taken from there what i need, in particular i have create this method:
public void postDeletion(int postId, int forumId, int userId) {
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
User u = um.selectById(userId);
// Post
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
Post p = pm.selectById(postId);
if (p.getId() == 0) {
return;
}
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
Topic t = TopicRepository.getTopic(new Topic(p.getTopicId()));
if (t == null) {
t = tm.selectRaw(p.getTopicId());
}
if (!TopicsCommon.isTopicAccessible(t.getForumId())) {
return;
}
pm.delete(p);
DataAccessDriver.getInstance().newUserDAO().decrementPosts(p.getUserId());
// Karma
KarmaDAO karmaDao = DataAccessDriver.getInstance().newKarmaDAO();
karmaDao.updateUserKarma(p.getUserId());
// It was the last remaining post in the topic?
int totalPosts = tm.getTotalPosts(p.getTopicId());
if (totalPosts > 0) {
// Topic
tm.decrementTotalReplies(p.getTopicId());
int maxPostId = tm.getMaxPostId(p.getTopicId());
if (maxPostId > -1) {
tm.setLastPostId(p.getTopicId(), maxPostId);
}
int minPostId = tm.getMinPostId(p.getTopicId());
if (minPostId > -1) {
tm.setFirstPostId(p.getTopicId(), minPostId);
}
// Forum
ForumDAO fm = DataAccessDriver.getInstance().newForumDAO();
maxPostId = fm.getMaxPostId(p.getForumId());
if (maxPostId > -1) {
fm.setLastPost(p.getForumId(), maxPostId);
}
}
PostRepository.remove(t.getId(), p.getId());
TopicRepository.loadMostRecentTopics();
ForumRepository.reloadForum(p.getForumId());
TopicRepository.clearCache(p.getForumId());
PostRepository.clearCache(t.getId());
ForumRepository.updateForumStats(t,u,p);
}
Thank you a lot, if can be useful i can post all the Complete deletion method,
best regards Federico
[originally posted on jforum.net by fscanu]