/** * @param $review_id * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function deleteReview($review_id) { try { $authorId = (int) $this->securityContext->getToken()->getUsername(); if (!is_int($authorId)) { return ['error' => true, 'errorText' => 'accessDenied']; } $review = $this->em->getRepository('Yasoon\\Site\\Entity\\ReviewEntity')->find($review_id); if (!$review) { return ['error' => true, 'errorText' => 'notFound']; } if ($review->getAuthorId() != $authorId && !$this->allf->isAdmin()) { return ['error' => true, 'errorText' => 'accessDenied']; } $this->em->remove($review); $this->em->flush(); $review_like = $this->em->getRepository('Yasoon\\Site\\Entity\\ReviewLikesEntity')->createQueryBuilder('l')->where('l.review_id = ' . $review_id)->getQuery()->getResult(); foreach ($review_like as $like) { $this->em->remove($like); $this->em->flush(); } // $friends = $this->em->getRepository('Yasoon\Site\Entity\AuthorEntity')->find($authorId)->getWriters(); // // foreach($friends as $friend) // { // $timeline = $this->em->createQueryBuilder() // ->select('t') // ->from('Yasoon\Site\Entity\TimelineEntity', 't') // ->where('t.author_id = :aid') // ->setParameter('aid', $friend->getId()) // ->getQuery()->getResult(); // if (count($timeline) < 1 || !is_object($timeline[0])) { // $timeline = (new TimelineEntity()) // ->setAuthorId($friend->getId()) // ->setPostsCount('0') // ->setQuestionsCount('0') // ->setAnswersCount('0'); // // $this->em->persist($timeline); // $this->em->flush(); // } // else // { // if($timeline[0]->getPostsCount() > 0) // { // $timeline[0]->setPostsCount(($timeline[0]->getPostsCount()*1) - 1); // $this->em->merge($timeline[0]); // $this->em->flush(); // } // } // } $data = json_encode(['_id' => 'review_' . $review_id]); $batchDataBody = '[' . $data . ']'; $this->allf->indexistoQueryDelete($batchDataBody); } catch (\Exception $e) { return ['error' => true, 'errorText' => $e->getMessage()]; } return ['error' => false, 'errorText' => '']; }
/** * @param int $id * @return array */ public function deleteQuestion($id) { $authorId = (int) $this->securityContext->getToken()->getUsername(); if (!is_int($authorId)) { return ['error' => true, 'errorText' => 'accessDenied']; } $question = $this->em->getRepository('Yasoon\\Site\\Entity\\QuestionEntity')->findById($id); if (!$question || $question[0]->getAuthorId() != $authorId) { return ['error' => true, 'errorText' => 'accessDenied']; } try { $this->em->remove($question[0]); $this->em->flush(); $data = json_encode(['_id' => 'questions_' . $id]); $batchDataBody = '[' . $data . ']'; $this->allf->indexistoQueryDelete($batchDataBody); return ['type' => 'delete', 'id' => $id]; } catch (\Exception $e) { return ['error' => true, 'errorText' => $e->getMessage()]; } }