/** * @param Application $app * @param $post_id int * * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response */ public function removePost(Application $app, $post_id) { $apiObject = new PostApi(new PostData($app)); $apiCommentObject = new CommentApi(new CommentData($app)); try { $result = $apiObject->delete($post_id); $resultComment = $apiCommentObject->deleteAllForPost($post_id); } catch (\InvalidArgumentException $e) { $message = $e->getMessage(); } catch (\UnexpectedValueException $e) { $message = $e->getMessage(); } if (isset($message)) { $app['session']->getFlashBag()->add('message', $message); } if (!isset($result) || !$result) { $app['session']->getFlashBag()->add('message', 'Failed to completely remove post.'); return $this->index($app); } $app['session']->getFlashBag()->add('message', 'Deleted post.'); return $this->index($app); }