public function podiumDeletePosts($posts)
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            foreach ($posts as $post) {
                if (!is_numeric($post) || $post < 1) {
                    throw new Exception('Incorrect post ID');
                }
                $nPost = Post::find()
                            ->where([
                                'id' => $post,
                                'thread_id' => $this->id,
                                'forum_id' => $this->forum->id
                            ])
                            ->limit(1)
                            ->one();
                if (!$nPost) {
                    throw new Exception('No post of given ID found');
                }
                if (!$nPost->delete()) {
                    throw new Exception('Post deleting error!');
                }
            }
            $wholeThread = false;
            if ($this->postsCount) {
                $this->updateCounters(['posts' => -count($posts)]);
                $this->forum->updateCounters(['posts' => -count($posts)]);
            } else {
                $wholeThread = true;
                if (!$this->delete()) {
                    throw new Exception('Thread deleting error!');
                }
                $this->forum->updateCounters(['posts' => -count($posts), 'threads' => -1]);
            }
            $transaction->commit();
            PodiumCache::clearAfter('postDelete');
            Log::info('Posts deleted', null, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
public function podiumDeletePosts($posts)
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            foreach ($posts as $post) {
                if (!is_numeric($post) || $post < 1) {
                    throw new Exception('Incorrect post ID');
                }
                $nPost = Post::find()
                            ->where([
                                'id' => $post,
                                'thread_id' => $this->id,
                                'forum_id' => $this->forum->id
                            ])
                            ->limit(1)
                            ->one();
                if (!$nPost) {
                    throw new Exception('No post of given ID found');
                }
                if (!$nPost->delete()) {
                    throw new Exception('Post deleting error!');
                }
            }
            $wholeThread = false;
            if ($this->postsCount) {
                $this->updateCounters(['posts' => -count($posts)]);
                $this->forum->updateCounters(['posts' => -count($posts)]);
            } else {
                $wholeThread = true;
                if (!$this->delete()) {
                    throw new Exception('Thread deleting error!');
                }
                $this->forum->updateCounters(['posts' => -count($posts), 'threads' => -1]);
            }
            $transaction->commit();
            PodiumCache::clearAfter('postDelete');
            Log::info('Posts deleted', null, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
public function podiumDeletePosts ( $ posts ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { foreach ( $ posts as $ post ) { if ( ! is_numeric ( $ post ) || $ post < 1 ) { throw new Exception ( 'Incorrect post ID' ) ; } $ nPost = Post :: find ( ) -> where ( [ 'id' => $ post , 'thread_id' => $ this -> id , 'forum_id' => $ this -> forum -> id ] ) -> limit ( 1 ) -> one ( ) ; if ( ! $ nPost ) { throw new Exception ( 'No post of given ID found' ) ; } if ( ! $ nPost -> delete ( ) ) { throw new Exception ( 'Post deleting error!' ) ; } } $ wholeThread = false ; if ( $ this -> postsCount ) { $ this -> updateCounters ( [ 'posts' => - count ( $ posts ) ] ) ; $ this -> forum -> updateCounters ( [ 'posts' => - count ( $ posts ) ] ) ; } else { $ wholeThread = true ; if ( ! $ this -> delete ( ) ) { throw new Exception ( 'Thread deleting error!' ) ; } $ this -> forum -> updateCounters ( [ 'posts' => - count ( $ posts ) , 'threads' => - 1 ] ) ; } $ transaction -> commit ( ) ; PodiumCache :: clearAfter ( 'postDelete' ) ; Log :: info ( 'Posts deleted' , null , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Performs thread posts delete with parent forum counters update.
@param array $posts posts IDs
@return bool
@throws Exception
@since 0.2
Performs thread posts delete with parent forum counters update .