public function deleteContent(AbstractClassContent $content, $mainContent = true)
    {
        if (!$this->getEntityManager()->contains($content)) {
            // Ensure $content is managed
            $content = $this->getEntityManager()
                    ->getRepository(AbstractClassContent::getFullClassname($content))
                    ->find($content->getUid());
        }

        if (null === $content) {
            return;
        }

        $parents = $this->getParentContents($content);
        $media = $this->_em->getRepository('BackBee\NestedNode\Media')->findOneBy([
            '_content' => $content->getUid(),
        ]);

        if ((1 >= count($parents) && null === $media) || true === $mainContent) {
            foreach ($content->getData() as $element) {
                if ($element instanceof AbstractClassContent) {
                    $this->deleteContent($element, false);
                }
            }

            if ($content instanceof ContentSet) {
                $content->clear();
            }

            foreach ($parents as $parent) {
                if (
                    true === $mainContent
                    && !($parent instanceof ContentSet)
                    && !$this->_em->getUnitOfWork()->isScheduledForDelete($parent)
                ) {
                    foreach ($parent->getData() as $key => $element) {
                        if ($element instanceof AbstractClassContent && $element === $content) {
                            $classname = get_class($element);
                            $newContent = new $classname();
                            $this->_em->persist($newContent);
                            $parent->$key = $newContent;
                        }
                    }
                } else {
                    $parent->unsetSubContent($content);
                }
            }

            $this->cleanUpContentHardDelete($content);
            $this->_em->remove($content->setMainNode(null));
        }
    }