/** * @param Form $form * @param Comment $comment * @param Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ private function processCommentForm(Form $form, Comment $comment, Request $request) { $slug = $comment->getPost()->getSlug(); if ($form->isValid()) { $this->getEm()->persist($comment); $this->getEm()->flush(); $param = ['slug' => $slug]; $this->addSuccess("lkeblog.success.comment.add"); return $this->redirectToRoute("lke_blog_post_view", $param); } return $this->viewAction($request, $slug); }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->getContainer()->get('doctrine')->getManager(); $parser = $this->getContainer()->get('lke_core.parse_csv'); $rows = $parser->parse(self::FILE); foreach ($rows as $row) { $comment = new Comment(); $comment->setUsername($row[self::USERNAME]); $comment->setContent($row[self::CONTENT]); $comment->setPost($this->getPost($row[self::POST_ID])); $em->persist($comment); } $em->flush(); $output->writeln("Comments loaded"); }