diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-11-22 18:22:10 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-11-22 18:22:10 -0500 |
commit | 77e10d25829f3523a168bf61424fac99a539f8be (patch) | |
tree | 9b3d274146fa9543c4734a945e61b9d975960ff6 /app/Model/Comment.php | |
parent | 15038cdb10f8c691edc7980fd1aed32dcbed3f9f (diff) |
Improve API to return id instead of a boolean
Diffstat (limited to 'app/Model/Comment.php')
-rw-r--r-- | app/Model/Comment.php | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/app/Model/Comment.php b/app/Model/Comment.php index cd361b1d..8ef89094 100644 --- a/app/Model/Comment.php +++ b/app/Model/Comment.php @@ -99,20 +99,25 @@ class Comment extends Base * * @access public * @param array $values Form values - * @return boolean + * @return boolean|integer */ public function create(array $values) { $values['date'] = time(); - if ($this->db->table(self::TABLE)->save($values)) { + return $this->db->transaction(function($db) use ($values) { + + if (! $db->table(Comment::TABLE)->save($values)) { + return false; + } + + $comment_id = (int) $db->getConnection()->getLastId(); + $values['id'] = $comment_id; - $values['id'] = $this->db->getConnection()->getLastId(); $this->event->trigger(self::EVENT_CREATE, $values); - return true; - } - return false; + return $comment_id; + }); } /** |