summaryrefslogtreecommitdiff
path: root/src/list_post_receive.php
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-10-31 20:53:21 +0000
committeruckelman <uckelman@nomic.net>2010-10-31 20:53:21 +0000
commit88d4c55ec38c68c07496ed059616b15622fc83e7 (patch)
treed54d2449e66d359cac3d4bc6171e072c4832b1f8 /src/list_post_receive.php
parent54551bc4cb0dee8549c229d18fca3bf3dc0d5c48 (diff)
Major refactoring to make bridge easier to test.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@7431 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src/list_post_receive.php')
-rw-r--r--src/list_post_receive.php90
1 files changed, 11 insertions, 79 deletions
diff --git a/src/list_post_receive.php b/src/list_post_receive.php
index 2072742..2c5ddc2 100644
--- a/src/list_post_receive.php
+++ b/src/list_post_receive.php
@@ -20,97 +20,29 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-# TODO: logging!
-# TODO: Refactor postMessage().
-
require_once('Log.php');
$logger = &Log::singleton('file', '/var/log/listbridge', 'one');
try {
- require_once('/var/www/bridge/src/Bridge.php');
- require_once('/var/www/bridge/src/MailmanLib.php');
- require_once('/var/www/bridge/src/MailmanMessage.php');
- require_once('/var/www/bridge/src/PhpBB3.php');
-
- # Read the message from STDIN
-# $url = 'php://stdin';
-
-# $input = read_raw_message($url);
-# $msg = new MailmanMessage($input);
-
if (!isset($_POST['message'])) {
throw new Exception('No message in POST');
}
- $msg = new MailmanMessage($_POST['message']);
-
- $messageId = $msg->getMessageId();
- $inReplyTo = $msg->getInReplyTo();
- $rererences = $msg->getReferences();
- $soruce = $msg->getSource();
-
- $logger->info($messageId . ' received from ' . $source);
-
- $bridge = new Bridge();
- $editId = $bridge->registerByMessageId($messageId, $inReplyTo);
-
- if ($editId === false) {
- # This message has already been processed, bail out
- $logger->info($messageId . ' already seen, skipping');
- exit;
- }
-
- try {
- $phpbb = new PhpBB3();
-
- $forumId = $topicId = null;
- $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);
- }
+ require_once(__DIR__ . '/BridgeConf.php');
+ require_once(__DIR__ . '/BridgeImpl.php');
+ require_once(__DIR__ . '/PhpBB3Conf.php');
+ require_once(__DIR__ . '/PhpBB3Impl.php');
+ require_once(__DIR__ . '/MailmanToPhpBB3.php');
- $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';
-
- $logger->info($messageId . ' replies to ' . $parentId);
- }
- else {
- # A message starting a new topic, post to default forum for its source
- $forumId = $bridge->getDefaultForumId($source);
- if ($forumId === false) {
- throw new Exception('unrecognized source: ' . $source);
- }
-
- $postType = 'post';
+ $msg = new MailmanMessage($_POST['message']);
- $logger->info($messageId . ' is a new post');
- }
+ $db = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB, DB_USER, DB_PASS);
+ $bridge = new BridgeImpl($db);
- $logger->info(
- $messageId . ' will be posted to ' . $forumId . ':' . $topicId);
-
- # Post the message to the forum
- $postId = $phpbb->postMessage($postType, $forumId, $topicId, $msg);
- $bridge->setPostId($messageId, $postId);
+ $phpbb = new PhpBB3Impl();
- $logger->info($messageId . ' posted as ' . $postId);
- }
- catch (Exception $e) {
- # Bridging failed, unregister message.
- $bridge->unregisterMessage($editId);
- throw $e;
- }
+ $conduit = new MailmanToPhpBB3($bridge, $phpbb, $logger);
+ $conduit->process($msg);
}
catch (Exception $e) {
$logger->err($e);