summaryrefslogtreecommitdiff
path: root/app/Model/Comment.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model/Comment.php')
-rw-r--r--app/Model/Comment.php17
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;
+ });
}
/**