Exemplo n.º 1
0
 /**
  * Deletes a post.
  *
  * @param Post $post The post that is to be deleted.
  * @return void
  */
 public function deleteAction(Post $post)
 {
     // Assert authorization
     $this->authenticationService->assertDeletePostAuthorization($post);
     // Delete the post.
     $postCount = $post->getTopic()->getPostCount();
     $this->postFactory->deletePost($post);
     $this->controllerContext->getFlashMessageQueue()->enqueue(new FlashMessage(Localization::translate('Post_Delete_Success')));
     // Notify observers and clear cache.
     $this->signalSlotDispatcher->dispatch('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Post', 'postDeleted', array('post' => $post));
     $this->clearCacheForCurrentPage();
     // If there is still on post left in the topic, redirect to the topic
     // view. If we have deleted the last post of a topic (i.e. the topic
     // itself), redirect to the forum view instead.
     if ($postCount > 1) {
         $this->redirect('show', 'Topic', NULL, array('topic' => $post->getTopic()));
     } else {
         $this->redirect('show', 'Forum', NULL, array('forum' => $post->getForum()));
     }
 }