summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-04-11 20:32:22 +0000
committeruckelman <uckelman@nomic.net>2010-04-11 20:32:22 +0000
commit6af518db11e22b8655e81ac9aa51486246f5d12c (patch)
treee6a3584f49aec10e3e8d5bffb29263f0b327e032 /src
parent8f30dcf18540991a722ae7e867c830903e706b83 (diff)
Unregister failed bridge attempts.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6682 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src')
-rw-r--r--src/M2F.php71
1 files changed, 44 insertions, 27 deletions
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";