private function deletePreviewPicture(\Novuscom\CMFBundle\Entity\Element $element) { $em = $this->getDoctrine()->getManager(); $previewPicture = $element->getPreviewPicture(); if ($previewPicture) { $element->setPreviewPicture(null); $em->persist($element); $em->remove($previewPicture); $fileName = $_SERVER['DOCUMENT_ROOT'] . '/upload/images/' . $previewPicture->getName(); $em->flush(); unlink($fileName); } }
private function deletePreviewPicture(\Novuscom\CMFBundle\Entity\Element $element) { $em = $this->getDoctrine()->getManager(); $previewPicture = $element->getPreviewPicture(); if ($previewPicture) { $element->setPreviewPicture(null); $em->persist($element); $em->remove($previewPicture); $dir = $this->get('kernel')->getRootDir() . '/../web/upload/images/'; $fileName = $dir . $previewPicture->getName(); $em->flush(); if (file_exists($fileName)) { unlink($fileName); } } }