public function podiumMoveTo($target = null)
    {
        $newParent = Forum::find()->where(['id' => $target])->limit(1)->one();
        if (empty($newParent)) {
            Log::error('No parent forum of given ID found', $this->id, __METHOD__);
            return false;
        }

        $postsCount = $this->postsCount;
        $transaction = Forum::getDb()->beginTransaction();
        try {
            $this->forum->updateCounters(['threads' => -1, 'posts' => -$postsCount]);
            $newParent->updateCounters(['threads' => 1, 'posts' => $postsCount]);
            $this->forum_id = $newParent->id;
            $this->category_id = $newParent->category_id;
            if (!$this->save()) {
                throw new Exception('Thread saving error!');
            }
            Post::updateAll(['forum_id' => $newParent->id], ['thread_id' => $this->id]);
            $transaction->commit();
            PodiumCache::clearAfter('threadMove');
            Log::info('Thread moved', $this->id, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
public function podiumMoveTo($target = null)
    {
        $newParent = Forum::find()->where(['id' => $target])->limit(1)->one();
        if (empty($newParent)) {
            Log::error('No parent forum of given ID found', $this->id, __METHOD__);
            return false;
        }

        $postsCount = $this->postsCount;
        $transaction = Forum::getDb()->beginTransaction();
        try {
            $this->forum->updateCounters(['threads' => -1, 'posts' => -$postsCount]);
            $newParent->updateCounters(['threads' => 1, 'posts' => $postsCount]);
            $this->forum_id = $newParent->id;
            $this->category_id = $newParent->category_id;
            if (!$this->save()) {
                throw new Exception('Thread saving error!');
            }
            Post::updateAll(['forum_id' => $newParent->id], ['thread_id' => $this->id]);
            $transaction->commit();
            PodiumCache::clearAfter('threadMove');
            Log::info('Thread moved', $this->id, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
public function podiumMoveTo ( $ target = null ) { $ newParent = Forum :: find ( ) -> where ( [ 'id' => $ target ] ) -> limit ( 1 ) -> one ( ) ; if ( empty ( $ newParent ) ) { Log :: error ( 'No parent forum of given ID found' , $ this -> id , __METHOD__ ) ; return false ; } $ postsCount = $ this -> postsCount ; $ transaction = Forum :: getDb ( ) -> beginTransaction ( ) ; try { $ this -> forum -> updateCounters ( [ 'threads' => - 1 , 'posts' => - $ postsCount ] ) ; $ newParent -> updateCounters ( [ 'threads' => 1 , 'posts' => $ postsCount ] ) ; $ this -> forum_id = $ newParent -> id ; $ this -> category_id = $ newParent -> category_id ; if ( ! $ this -> save ( ) ) { throw new Exception ( 'Thread saving error!' ) ; } Post :: updateAll ( [ 'forum_id' => $ newParent -> id ] , [ 'thread_id' => $ this -> id ] ) ; $ transaction -> commit ( ) ; PodiumCache :: clearAfter ( 'threadMove' ) ; Log :: info ( 'Thread moved' , $ this -> id , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Performs thread move with counters update.
@param int $target new parent forum's ID
@return bool
@since 0.2
Performs thread move with counters update .