original_string: public function podiumNew($previous = null)
      {
          $transaction = static::getDb()->beginTransaction();
          try {
              $id = null;
              $loggedId = User::loggedId();
              $sameAuthor = !empty($previous->author_id) && $previous->author_id == $loggedId;
              if ($sameAuthor && Podium::getInstance()->podiumConfig->get('merge_posts')) {
                  $separator = '<hr>';
                  if (Podium::getInstance()->podiumConfig->get('use_wysiwyg') == '0') {
                      $separator = "\n\n---\n";
                  }
                  $previous->content .= $separator . $this->content;
                  $previous->edited = 1;
                  $previous->touch('edited_at');
                  if (!$previous->save()) {
                      throw new Exception('Previous Post saving error!');
                  }
                  $previous->markSeen(false);
                  $previous->thread->touch('edited_post_at');
                  $id = $previous->id;
                  $thread = $previous->thread;
              } else {
                  if (!$this->save()) {
                      throw new Exception('Post saving error!');
                  }
                  $this->markSeen(!$sameAuthor);
                  if (!$this->forum->updateCounters(['posts' => 1])) {
                      throw new Exception('Forum Post counter adding error!');
                  }
                  if (!$this->thread->updateCounters(['posts' => 1])) {
                      throw new Exception('Thread Post counter adding error!');
                  }
                  $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 = $loggedId;
                  $subscription->thread_id = $thread->id;
                  $subscription->post_seen = Subscription::POST_SEEN;
                  if (!$subscription->save()) {
                      throw new Exception('Subscription saving error!');
                  }
              }
              $transaction->commit();
              PodiumCache::clearAfter('newPost');
              Log::info('Post added', $id, __METHOD__);
              return true;
          } catch (Exception $e) {
              $transaction->rollBack();
              Log::error($e->getMessage(), null, __METHOD__);
          }
          return false;
      }
code: public function podiumNew($previous = null)
      {
          $transaction = static::getDb()->beginTransaction();
          try {
              $id = null;
              $loggedId = User::loggedId();
              $sameAuthor = !empty($previous->author_id) && $previous->author_id == $loggedId;
              if ($sameAuthor && Podium::getInstance()->podiumConfig->get('merge_posts')) {
                  $separator = '<hr>';
                  if (Podium::getInstance()->podiumConfig->get('use_wysiwyg') == '0') {
                      $separator = "\n\n---\n";
                  }
                  $previous->content .= $separator . $this->content;
                  $previous->edited = 1;
                  $previous->touch('edited_at');
                  if (!$previous->save()) {
                      throw new Exception('Previous Post saving error!');
                  }
                  $previous->markSeen(false);
                  $previous->thread->touch('edited_post_at');
                  $id = $previous->id;
                  $thread = $previous->thread;
              } else {
                  if (!$this->save()) {
                      throw new Exception('Post saving error!');
                  }
                  $this->markSeen(!$sameAuthor);
                  if (!$this->forum->updateCounters(['posts' => 1])) {
                      throw new Exception('Forum Post counter adding error!');
                  }
                  if (!$this->thread->updateCounters(['posts' => 1])) {
                      throw new Exception('Thread Post counter adding error!');
                  }
                  $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 = $loggedId;
                  $subscription->thread_id = $thread->id;
                  $subscription->post_seen = Subscription::POST_SEEN;
                  if (!$subscription->save()) {
                      throw new Exception('Subscription saving error!');
                  }
              }
              $transaction->commit();
              PodiumCache::clearAfter('newPost');
              Log::info('Post added', $id, __METHOD__);
              return true;
          } catch (Exception $e) {
              $transaction->rollBack();
              Log::error($e->getMessage(), null, __METHOD__);
          }
          return false;
      }
code_tokens: public function podiumNew ( $ previous = null ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { $ id = null ; $ loggedId = User :: loggedId ( ) ; $ sameAuthor = ! empty ( $ previous -> author_id ) && $ previous -> author_id == $ loggedId ; if ( $ sameAuthor && Podium :: getInstance ( ) -> podiumConfig -> get ( 'merge_posts' ) ) { $ separator = '<hr>' ; if ( Podium :: getInstance ( ) -> podiumConfig -> get ( 'use_wysiwyg' ) == '0' ) { $ separator = "\n\n---\n" ; } $ previous -> content .= $ separator . $ this -> content ; $ previous -> edited = 1 ; $ previous -> touch ( 'edited_at' ) ; if ( ! $ previous -> save ( ) ) { throw new Exception ( 'Previous Post saving error!' ) ; } $ previous -> markSeen ( false ) ; $ previous -> thread -> touch ( 'edited_post_at' ) ; $ id = $ previous -> id ; $ thread = $ previous -> thread ; } else { if ( ! $ this -> save ( ) ) { throw new Exception ( 'Post saving error!' ) ; } $ this -> markSeen ( ! $ sameAuthor ) ; if ( ! $ this -> forum -> updateCounters ( [ 'posts' => 1 ] ) ) { throw new Exception ( 'Forum Post counter adding error!' ) ; } if ( ! $ this -> thread -> updateCounters ( [ 'posts' => 1 ] ) ) { throw new Exception ( 'Thread Post counter adding error!' ) ; } $ 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 = $ loggedId ; $ subscription -> thread_id = $ thread -> id ; $ subscription -> post_seen = Subscription :: POST_SEEN ; if ( ! $ subscription -> save ( ) ) { throw new Exception ( 'Subscription saving error!' ) ; } } $ transaction -> commit ( ) ; PodiumCache :: clearAfter ( 'newPost' ) ; Log :: info ( 'Post added' , $ id , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
docstring: Performs new post creation and subscription.
  Depending on the settings previous post can be merged.
  @param Post $previous previous post
  @return bool
  @since 0.2
docstring_tokens: Performs new post creation and subscription . Depending on the settings previous post can be merged .