/** * Create a new node and its children * * @param object Hierarchy $newHierarchy * @param object Node $oldNode * @param optional object Id $parentId * @return void * @access protected * @since 4/17/08 */ protected function addNode(Hierarchy $newHierarchy, Node $oldNode, Id $parentId = null) { // If it has already been created, get it and try to set its parent try { $newNode = $newHierarchy->getNode($oldNode->getId()); if (!is_null($parentId)) { try { $newNode->addParent($parentId); } catch (Exception $e) { // Do nothing if the child already exists if ($e->getMessage() != "A child with the given id already exists!") { throw $e; } } } } catch (UnknownIdException $e) { if (is_null($parentId)) { $newNode = $newHierarchy->createRootNode($oldNode->getId(), $oldNode->getType(), $oldNode->getDisplayName(), $oldNode->getDescription()); } else { $newNode = $newHierarchy->createNode($oldNode->getId(), $parentId, $oldNode->getType(), $oldNode->getDisplayName(), $oldNode->getDescription()); } $this->nodeStatus->updateStatistics(); } $oldChildren = $oldNode->getChildren(); while ($oldChildren->hasNext()) { $oldChild = $oldChildren->next(); $this->addNode($newHierarchy, $oldChild, $newNode->getId()); } }