From cb5ffae7c9c93513f2fa88a059292c7d37761ae4 Mon Sep 17 00:00:00 2001 From: uckelman Date: Sun, 31 Oct 2010 22:40:28 +0000 Subject: Refactored. git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@7436 67b53d14-2c14-4ace-a08f-0dab2b34000c --- src/MailmanToPhpBB3.php | 73 +++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/MailmanToPhpBB3.php b/src/MailmanToPhpBB3.php index 54c0ce1..9d64878 100644 --- a/src/MailmanToPhpBB3.php +++ b/src/MailmanToPhpBB3.php @@ -54,39 +54,8 @@ class MailmanToPhpBB3 { } try { - $forumId = $topicId = null; - $postType = null; - - if ($inReplyTo) { - # Possibly a reply to an existing topic - $parentId = $this->bridge->getPostId($inReplyTo); - if ($parentId === false) { - throw new Exception('unrecognized Reply-To: ' . $inReplyTo); - } - - $ids = $this->phpbb->getTopicAndForumIds($parentId); - if ($ids === false) { - throw new Exception('unrecognized parent id: ' . $parentId); - } - - # Found the parent's forum and topic, post to those - $forumId = $ids['forum_id']; - $topicId = $ids['topic_id']; - $postType = 'reply'; - - $this->logger->info($messageId . ' replies to ' . $parentId); - } - else { - # A message starting a new topic, post to default forum for its source - $forumId = $this->bridge->getDefaultForumId($source); - if ($forumId === false) { - throw new Exception('unrecognized source: ' . $source); - } - - $postType = 'post'; - - $this->logger->info($messageId . ' is a new post'); - } + list($postType, $forumId, $topicId) = + find_destination($source, $inReplyTo, $messageId); $this->logger->info( $messageId . ' will be posted to ' . $forumId . ':' . $topicId); @@ -103,6 +72,44 @@ class MailmanToPhpBB3 { throw $e; } } + + protected function find_destination($source, $inReplyTo, $messageId) { + $forumId = $topicId = null; + $postType = null; + + if ($inReplyTo) { + # Possibly a reply to an existing topic + $parentId = $this->bridge->getPostId($inReplyTo); + if ($parentId === false) { + throw new Exception('unrecognized Reply-To: ' . $inReplyTo); + } + + $ids = $this->phpbb->getTopicAndForumIds($parentId); + if ($ids === false) { + throw new Exception('unrecognized parent id: ' . $parentId); + } + + # Found the parent's forum and topic, post to those + $forumId = $ids['forum_id']; + $topicId = $ids['topic_id']; + $postType = 'reply'; + + $this->logger->info($messageId . ' replies to ' . $parentId); + } + else { + # A message starting a new topic, post to default forum for its source + $forumId = $this->bridge->getDefaultForumId($source); + if ($forumId === false) { + throw new Exception('unrecognized source: ' . $source); + } + + $postType = 'post'; + + $this->logger->info($messageId . ' is a new post'); + } + + return array($postType, $forumId, $topicId); + } } ?> -- cgit v1.2.3