From 6af518db11e22b8655e81ac9aa51486246f5d12c Mon Sep 17 00:00:00 2001 From: uckelman Date: Sun, 11 Apr 2010 20:32:22 +0000 Subject: Unregister failed bridge attempts. git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6682 67b53d14-2c14-4ace-a08f-0dab2b34000c --- src/M2F.php | 71 ++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/M2F.php b/src/M2F.php index 7059137..4d23861 100644 --- a/src/M2F.php +++ b/src/M2F.php @@ -12,44 +12,61 @@ try { $input = read_raw_message($url); $msg = new MailmanMessage($input); - $bridge = new Bridge(); - $messageId = $msg->getMessageId(); $inReplyTo = $msg->getInReplyTo(); $rererences = $msg->getReferences(); + $bridge = new Bridge(); $seen = !$bridge->registerMessage($messageId, $inReplyTo, $references); - if ($seen) { - # This message has already been processed. - print 'Message id already seen, skipping: ' . $messageId . "\n"; - exit; - } + try { + if ($seen) { + # This message has already been processed, bail out + print 'Message id already seen, skipping: ' . $messageId . "\n"; + exit; + } + + $phpbb = new PhpBB3(); - $phpbb = new PhpBB3(); + $forumId = $topicId = -1; + $postType = null; - $forumId = $topicId = -1; - $postType = null; + if ($inReplyTo) { + # Possibly a reply to an existing topic + $parentId = $bridge->getPostId($inReplyTo); + if ($parentId === false) { + throw new Exception('unrecognized reply-to: ' . $inReplyTo); + } + + $ids = $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'; + } + else { + # A message starting a new topic, post to default forum for its source + $forumId = $bridge->getDefaultForumId($msg->getSource()); + if ($forumId === false) { + throw new Exception('unrecognized source: ' . $msg->getSource()); + } + + $postType = 'post'; + } - if ($inReplyTo) { - # A reply to an existing topic - # FIXME: we don't want exceptions here? - $parentId = $bridge->getPostId($inReplyTo); - $ids = $phpbb->getTopicAndForumIds($parentId); - $forumId = $ids['forum_id']; - $topicId = $ids['topic_id']; - $postType = 'reply'; + # Post the message to the forum + $postId = $phpbb->postMessage($postType, $forumId, $topicId, $msg); + $bridge->setPostId($messageId, $postId); } - else { - # A message starting a new topic - $forumId = $bridge->getDefaultForumId($msg->getSource()); - $postType = 'post'; + catch (Exception $e) { + # Bridging failed, unregister message. + $bridge->unregisterMessage($messageId); + throw $e; } - - # Post the message to the forum - $postId = $phpbb->postMessage($postType, $forumId, $topicId, $msg); - - $bridge->setPostId($messageId, $postId); } catch (Exception $e) { print "$e\n"; -- cgit v1.2.3