/** * @param Topic $topic * * @return bool */ public function deleteTopic(Topic $topic) { if ($topic->deleted_at == null) { $topic->forum->decrement('num_topics'); $topic->forum->decrement('num_posts', $topic->num_posts); if ($topic->user_id > 0) { $topic->author->decrement('num_topics'); } $success = $topic->delete(); if ($success) { if ($topic->last_post_id == $topic->forum->last_post_id) { $this->forumRepository->updateLastPost($topic->forum); } } return $success; } else { // First we need to remove old foreign keys - otherwise we can't delete posts $topic->update(['first_post_id' => null, 'last_post_id' => null]); // Now delete the posts for this topic $this->postRepository->deletePostsForTopic($topic); // Don't forget the polls if ($topic->has_poll) { $this->pollRepository->remove($topic->poll); } // And finally delete the topic $topic->forceDelete(); } return true; }
/** * Update the last post for this forum * * @param Forum $forum The forum to update * @param Post $post * * @return void */ public function updateLastPost(Forum $forum, Post $post = null) { // TODO: It'd be better to update the cache instead of forgetting it $this->cache->forget('forums.index_tree'); $this->cache->forget('forums.all'); $this->decoratedRepository->updateLastPost($forum, $post); }
/** * Restore a topic * * @param Topic $topic The topic to restore * * @return mixed */ public function restoreTopic(Topic $topic) { $topic->forum->increment('num_topics'); $topic->forum->increment('num_posts', $topic->num_posts); if ($topic->user_id > 0) { $topic->author->increment('num_topics'); } $success = $topic->restore(); if ($success) { if ($topic->last_post_id > $topic->forum->last_post_id) { $this->forumRepository->updateLastPost($topic->forum, $topic->lastPost); } } return $success; }
/** * Restore a post * * @param Post $post The post to restore * * @return mixed */ public function restorePost(Post $post) { $post->topic->increment('num_posts'); $post->topic->forum->increment('num_posts'); if ($post->user_id > 0) { $post->author->increment('num_posts'); } $success = $post->restore(); if ($success) { if ($post->id > $post->topic->last_post_id) { $post->topic->update(['last_post_id' => $post->id]); } if ($post->id > $post->topic->forum->last_post_id) { $this->forumRepository->updateLastPost($post->topic->forum, $post); } } return $success; }