summaryrefslogtreecommitdiff
path: root/src/Bridge.php
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-04-11 19:54:15 +0000
committeruckelman <uckelman@nomic.net>2010-04-11 19:54:15 +0000
commit9e127046513b0cad9bded2c320b325795b94ad3a (patch)
tree4fbf2705ed909b5e483c51ae75f5b0f436b7acf3 /src/Bridge.php
parentf214bc73c73c09fa0ae1b2d0d61b78629a587ae9 (diff)
Refactored.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6674 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src/Bridge.php')
-rw-r--r--src/Bridge.php40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/Bridge.php b/src/Bridge.php
index 05689f8..6b83230 100644
--- a/src/Bridge.php
+++ b/src/Bridge.php
@@ -1,6 +1,7 @@
<?php
require_once(__DIR__ . '/BridgeConf.php');
+require_once(__DIR__ . '/Util.php');
class Bridge {
protected $db;
@@ -13,29 +14,28 @@ class Bridge {
}
public function getPostId($messageId) {
+ throw_if_null($messageId);
+
$sql = 'SELECT post_id FROM posts ' .
'WHERE message_id = ' . $this->db->quote($messageId);
$row = $this->get_exactly_one_row($sql);
- return $row['post_id'];
+ return $row ? $row['post_id'] : false;
}
public function getMessageId($postId) {
+ throw_if_null($postId);
+
$sql = 'SELECT message_id FROM posts ' .
'WHERE post_id = ' . $this->db->quote($postId);
$row = $this->get_exactly_one_row($sql);
- return $row['message_id'];
+ return $row ? $row['message_id'] : false;
}
public function setPostId($messageId, $postId) {
- if ($messageId === null) {
- throw new Exception('message id is null');
- }
-
- if ($postId === null) {
- throw new Exception('post id is null');
- }
+ throw_if_null($messageId);
+ throw_if_null($postId);
$sql = 'UPDATE posts SET ' .
'post_id = ' . $postId . ' ' .
@@ -49,23 +49,23 @@ class Bridge {
}
public function getDefaultForumId($list) {
+ throw_if_null($list);
+
$sql = 'SELECT forum_id FROM forums ' .
'WHERE list_name = ' . $this->db->quote($list);
$row = $this->get_exactly_one_row($sql);
- return $row['forum_id'];
+ return $row ? $row['forum_id'] : false;
}
- public function registerMessage($messageId, $inReplyTo, $refs) {
- if ($messageId === null) {
- throw new Exception('message id is null');
- }
+ public function registerMessage($messageId, $inReplyTo, $references) {
+ throw_if_null($messageId);
$sql = 'INSERT IGNORE INTO posts ' .
'(message_id, in_reply_to, refs) ' .
'VALUES (' . $this->db->quote($messageId) . ', '
- . $this->db->quote($inReplyTo) . ', '
- . $this->db->quote($refs) . ')';
+ . $this->quote($inReplyTo) . ', '
+ . $this->quote($references) . ')';
$count = $this->db->exec($sql);
@@ -80,17 +80,19 @@ class Bridge {
switch (count($rows)) {
case 0:
- throw new Exception("No rows returned: $sql");
- break;
+ return false;
case 1:
return $rows[0];
default:
throw new Exception("Too many rows returned: $sql");
- break;
}
}
+
+ protected function quote($arg) {
+ return $arg === null ? 'NULL' : $this->db->quote($arg);
+ }
}
?>