Exemplo n.º 1
0
 /**
  * @param PostModel $postModel
  * @throws \Doctrine\DBAL\DBALException
  */
 public function publishNewThread(PostModel $postModel)
 {
     $thread = (new Thread())->setForumid($postModel->getForumId())->setTitle($postModel->getTitle())->setOpen(1)->setVisible(1)->setTaglist($postModel->getTaglist());
     $this->getManager()->persist($thread);
     $this->getManager()->flush();
     $post = (new Post())->setThreadid($thread->getThreadid())->setParentid(0)->setUsername($postModel->getLastPosterName())->setUserid($postModel->getLastPosterId())->setTitle($postModel->getTitle())->setPagetext($postModel->getPageText())->setVisible(1)->setDateline(time());
     $this->getManager()->persist($post);
     try {
         $this->getManager()->flush();
     } catch (\Exception $e) {
         $this->container->get("logger")->error(__METHOD__ . " " . $e->getMessage());
     }
     try {
         $thread = $this->getManager()->getRepository("ImmortalchessNetBundle:Thread")->find($post->getThreadid());
     } catch (ThreadNotFoundException $e) {
         $this->container->get("logger")->error("Thread #" . $post->getThreadid() . " is not found");
         return;
     }
     $thread->setLastpostid($post->getPostid())->setLastpost($post->getDateline())->setLastposter($post->getUsername())->setThreadid($post->getThreadid())->setReplycount($thread->getReplycount() + 1);
     $this->getManager()->persist($thread);
     try {
         $forum = $this->getManager()->getRepository("ImmortalchessNetBundle:Forum")->find($thread->getForumid());
     } catch (ForumNotFoundException $e) {
         $this->container->get("logger")->error("Forum #" . $thread->getForumid() . " is not found");
         return;
     }
     $forum->setLastpostid($post->getPostid())->setLastpost($post->getDateline())->setLastposter($post->getUsername())->setLastthreadid($post->getThreadid())->setLastthread($thread->getTitle());
     $this->getManager()->persist($forum);
     try {
         $this->getManager()->flush();
     } catch (\Exception $e) {
         $this->container->get("logger")->error(__METHOD__ . " " . $e->getMessage());
     }
 }