diff options
author | uckelman <uckelman@nomic.net> | 2010-10-31 22:40:28 +0000 |
---|---|---|
committer | uckelman <uckelman@nomic.net> | 2010-10-31 22:40:28 +0000 |
commit | cb5ffae7c9c93513f2fa88a059292c7d37761ae4 (patch) | |
tree | 278ac4d7b5bee416aebe63100fb3e9974dd5b5e8 | |
parent | 264a6ecb49961428ecbb7f5de752ae08435946a2 (diff) |
Refactored.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@7436 67b53d14-2c14-4ace-a08f-0dab2b34000c
-rw-r--r-- | src/MailmanToPhpBB3.php | 73 |
1 files changed, 40 insertions, 33 deletions
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); + } } ?> |