Ejemplo n.º 1
0
 /**
  * @param ContentEntity $content
  * @param ContentEntity $parentContent
  */
 function cloneContent(ContentEntity $content, ContentEntity $parentContent = null)
 {
     $newContent = clone $content;
     $newContent->setTreeParent($parentContent);
     $parentId = null;
     if ($parentContent != null) {
         $parentId = $parentContent->getId();
     }
     if ($content->getFile() != null) {
         $newFile = $this->mm()->cloneMedia($content->getFile());
         $newContent->setFile($newFile);
     }
     $existingSlug = $newContent->getSlug();
     $newSlug = $this->generateSlug($newContent->getTitle(), $newContent->getType(), $parentId);
     if ($newSlug != $existingSlug) {
         $newContent->setTitle($content->getTitle() . ' Copy');
         $newSlug = $this->generateSlug($newContent->getTitle(), $newContent->getType(), $parentId);
         $newContent->setSlug($newSlug);
     }
     $this->em()->persist($newContent);
     $existingRelation = $content->getRelation();
     if (!empty($existingRelation)) {
         foreach ($existingRelation as $relation) {
             $newRelation = clone $relation;
             $newRelation->setContent($newContent);
             $newContent->addRelation($newRelation);
             $this->em()->persist($newRelation);
         }
     }
     $existingMeta = $content->getMeta();
     if (!empty($existingMeta)) {
         foreach ($existingMeta as $meta) {
             $newMeta = clone $meta;
             $newMeta->setContent($newContent);
             $newContent->addMeta($newMeta);
             $this->em()->persist($newMeta);
         }
     }
     $this->em()->flush();
 }