1 /*****************************************2 * *3 * JBoss Portal: The OpenSource Portal *4 * *5 * Forums JBoss Portlet *6 * *7 * Distributable under GPL license. *8 * See terms of license at gnu.org. *9 * *10 *****************************************/11 package org.jboss.portlet.forums.commands.moderation;12 13 14 /**15 * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>16 * @version $Revision: 1.1.1.1 $17 */18 public class MoveTopicCommand // extends AbstractCommand19 {20 /*21 public TopicEJBLocal topic;22 public Homes homes;23 public ForumEJBLocal source = null;24 public ForumEJBLocal target = null;25 public boolean leaveShadow;26 public Result execute()27 {28 if (topic.getStatus() != BBConstants.TOPIC_MOVED)29 {30 topic.setForum(target);31 for (Iterator it2 = topic.getPosts().iterator(); it2.hasNext();)32 {33 PostEJBLocal movedPostEJB = (PostEJBLocal)it2.next();34 movedPostEJB.setForum(target);35 }36 // a finder will force the to flush the changes to the store37 // per the specification 10.5.3 2.0 so we can use them safely38 // then we update the last post field on the source39 try40 {41 source.setLastPost(homes.post.findLastPost(source));42 }43 catch(ObjectNotFoundException e)44 {45 // no last post46 source.setLastPost(null);47 }48 catch(FinderException e)49 {50 log.error("Cannot find last posts for the forum " + source.getId(), e);51 return TYPE_CANNOT_MOVE_TOPIC;52 }53 // and the destination54 try55 {56 target.setLastPost(homes.post.findLastPost(target));57 }58 catch(ObjectNotFoundException e)59 {60 target.setLastPost(null);61 // no last post62 // bad situation ???63 }64 catch(FinderException e)65 {66 log.error("Cannot find last posts for the forum " + source.getId(), e);67 return TYPE_CANNOT_MOVE_TOPIC;68 }69 // now we update the fields70 int replies = topic.getReplies();71 source.setTopicSize(source.getTopicSize() - 1);72 source.setPostSize(source.getPostSize() - 1 - replies);73 target.setTopicSize(target.getTopicSize() + 1);74 target.setPostSize(target.getPostSize() + replies + 1);75 //76 if (leaveShadow)77 {78 // $sql = "INSERT INTO " . TOPICS_TABLE . " (forum_id, topic_title, topic_poster, topic_time, topic_status, topic_type, topic_vote, topic_views, topic_replies, topic_first_post_id, topic_last_post_id, topic_moved_id)79 // VALUES ($old_forum_id, '" . addslashes(str_replace("\'", "''", $row[$i]['topic_title'])) . "', '" . str_replace("\'", "''", $row[$i]['topic_poster']) . "', " . $row[$i]['topic_time'] . ", " . TOPIC_MOVED . ", " . POST_NORMAL . ", " . $row[$i]['topic_vote'] . ", " . $row[$i]['topic_views'] . ", " . $row[$i]['topic_replies'] . ", " . $row[$i]['topic_first_post_id'] . ", " . $row[$i]['topic_last_post_id'] . ", $topic_id)";80 // if ( !$db->sql_query($sql) )81 // {82 // message_die(GENERAL_ERROR, 'Could not insert shadow topic', '', __LINE__, __FILE__, $sql);83 // }84 // todo85 // TopicEJBLocal shadowEJB = topicHome.create(86 // movedEJB.getTitle(),87 // movedEJB.getPoster(),88 // movedEJB.getCreationDate(),89 // sourceForumEJB,90 // TOPIC_MOVED,91 // POST_NORMAL,92 // movedEJB.getVote()93 // );94 }95 }96 // // Sync the forum indexes97 // sync('forum', $new_forum_id);98 // sync('forum', $old_forum_id);99 // message = "${bb.Topics_moved}<br/><br/>";100 return TYPE_TOPIC_MOVED;101 }102 */103 }