/** * Performs new post creation and subscription. * If previous post in thread has got the same author posts are merged. * @param Post $previous previous post * @return boolean * @throws Exception * @since 0.2 */ public function podiumNew($previous = null) { $transaction = static::getDb()->beginTransaction(); try { $id = null; if (!empty($previous) && $previous->author_id == User::loggedId()) { $previous->content .= '<hr>' . $this->content; $previous->edited = 1; $previous->touch('edited_at'); if ($previous->save()) { $previous->markSeen(); $previous->thread->touch('edited_post_at'); $id = $previous->id; $thread = $previous->thread; } } else { if ($this->save()) { $this->markSeen(); $this->forum->updateCounters(['posts' => 1]); $this->thread->updateCounters(['posts' => 1]); $this->thread->touch('new_post_at'); $this->thread->touch('edited_post_at'); $id = $this->id; $thread = $this->thread; } } if (empty($id)) { throw new Exception('Saved Post ID missing'); } Subscription::notify($thread->id); if ($this->subscribe && !$thread->subscription) { $subscription = new Subscription(); $subscription->user_id = User::loggedId(); $subscription->thread_id = $thread->id; $subscription->post_seen = Subscription::POST_SEEN; $subscription->save(); } $transaction->commit(); Cache::clearAfter('newPost'); Log::info('Post added', $id, __METHOD__); return true; } catch (Exception $e) { $transaction->rollBack(); Log::error($e->getMessage(), null, __METHOD__); } return false; }