Пример #1
0
 private function duplicateRec(Node $node, $level)
 {
     $childrenArray = [];
     $sourceArray = [];
     $childs = new ArrayCollection($node->getChildren()->toArray());
     $node->getChildren()->clear();
     foreach ($childs as $child) {
         $childrenArray[] = $this->duplicateRec($child, $level + 1);
     }
     $nodeSources = new ArrayCollection($node->getNodeSources()->toArray());
     $node->getNodeSources()->clear();
     foreach ($nodeSources as $nodeSource) {
         $nodeSource->setNode(null);
         $tran = Kernel::getService('em')->merge($nodeSource->getTranslation());
         $nodeSource->setTranslation($tran);
         Kernel::getService('em')->persist($nodeSource);
         $nsdocs = $nodeSource->getDocumentsByFields();
         foreach ($nsdocs as $nsdoc) {
             $nsdoc->setNodeSource($nodeSource);
             $doc = Kernel::getService('em')->merge($nsdoc->getDocument());
             $nsdoc->setDocument($doc);
             $f = Kernel::getService('em')->merge($nsdoc->getField());
             $nsdoc->setField($f);
             Kernel::getService('em')->persist($nsdoc);
         }
         Kernel::getService('em')->flush();
         $sourceArray[] = $nodeSource;
     }
     $nodetype = Kernel::getService('em')->merge($node->getNodeType());
     $node->setNodeType($nodetype);
     $node->setParent(null);
     Kernel::getService('em')->persist($node);
     foreach ($childrenArray as $child) {
         $child->setParent($node);
     }
     foreach ($sourceArray as $source) {
         $source->setNode($node);
     }
     Kernel::getService('em')->flush();
     return $node;
 }