src/wcmf/application/controller/CopyController.php
protected function copyNode(ObjectId $oid) {
    $logger = $this->getLogger();
    if ($logger->isDebugEnabled()) {
      $logger->debug("Copying node ".$oid);
    }
    $persistenceFacade = $this->getPersistenceFacade();

    // load the original node
    $node = $persistenceFacade->load($oid);
    if ($node == null) {
      throw new PersistenceException("Can't load node '".$oid."'");
    }

    // check if we already have a copy of the node
    $nodeCopy = $this->getCopy($node->getOID());
    if ($nodeCopy == null) {
      // if not, create it
      $nodeCopy = $persistenceFacade->create($node->getType());
      $node->copyValues($nodeCopy, false);
    }

    // save copy
    $this->registerCopy($node, $nodeCopy);

    if ($logger->isInfoEnabled()) {
      $logger->info("Copied: ".$node->getOID()." to ".$nodeCopy->getOID());
    }
    if ($logger->isDebugEnabled()) {
      $logger->debug($nodeCopy->__toString());
    }

    // create the connections to already copied relatives
    // this must be done after saving the node in order to have a correct oid
    $mapper = $node->getMapper();
    $relations = $mapper->getRelations();
    foreach ($relations as $relation) {
      if ($relation->getOtherNavigability()) {
        $otherRole = $relation->getOtherRole();
        $relativeValue = $node->getValue($otherRole);
        $relatives = $relation->isMultiValued() ? $relativeValue :
                ($relativeValue != null ? [$relativeValue] : []);
        foreach ($relatives as $relative) {
          $copiedRelative = $this->getCopy($relative->getOID());
          if ($copiedRelative != null) {
            $nodeCopy->addNode($copiedRelative, $otherRole);
            if ($logger->isDebugEnabled()) {
              $logger->debug("Added ".$copiedRelative->getOID()." to ".$nodeCopy->getOID());
              $logger->debug($copiedRelative->__toString());
            }
          }
        }
      }
    }
    return $nodeCopy;
  }
protected function copyNode(ObjectId $oid) {
    $logger = $this->getLogger();
    if ($logger->isDebugEnabled()) {
      $logger->debug("Copying node ".$oid);
    }
    $persistenceFacade = $this->getPersistenceFacade();

    // load the original node
    $node = $persistenceFacade->load($oid);
    if ($node == null) {
      throw new PersistenceException("Can't load node '".$oid."'");
    }

    // check if we already have a copy of the node
    $nodeCopy = $this->getCopy($node->getOID());
    if ($nodeCopy == null) {
      // if not, create it
      $nodeCopy = $persistenceFacade->create($node->getType());
      $node->copyValues($nodeCopy, false);
    }

    // save copy
    $this->registerCopy($node, $nodeCopy);

    if ($logger->isInfoEnabled()) {
      $logger->info("Copied: ".$node->getOID()." to ".$nodeCopy->getOID());
    }
    if ($logger->isDebugEnabled()) {
      $logger->debug($nodeCopy->__toString());
    }

    // create the connections to already copied relatives
    // this must be done after saving the node in order to have a correct oid
    $mapper = $node->getMapper();
    $relations = $mapper->getRelations();
    foreach ($relations as $relation) {
      if ($relation->getOtherNavigability()) {
        $otherRole = $relation->getOtherRole();
        $relativeValue = $node->getValue($otherRole);
        $relatives = $relation->isMultiValued() ? $relativeValue :
                ($relativeValue != null ? [$relativeValue] : []);
        foreach ($relatives as $relative) {
          $copiedRelative = $this->getCopy($relative->getOID());
          if ($copiedRelative != null) {
            $nodeCopy->addNode($copiedRelative, $otherRole);
            if ($logger->isDebugEnabled()) {
              $logger->debug("Added ".$copiedRelative->getOID()." to ".$nodeCopy->getOID());
              $logger->debug($copiedRelative->__toString());
            }
          }
        }
      }
    }
    return $nodeCopy;
  }
protected function copyNode ( ObjectId $ oid ) { $ logger = $ this -> getLogger ( ) ; if ( $ logger -> isDebugEnabled ( ) ) { $ logger -> debug ( "Copying node " . $ oid ) ; } $ persistenceFacade = $ this -> getPersistenceFacade ( ) ; // load the original node $ node = $ persistenceFacade -> load ( $ oid ) ; if ( $ node == null ) { throw new PersistenceException ( "Can't load node '" . $ oid . "'" ) ; } // check if we already have a copy of the node $ nodeCopy = $ this -> getCopy ( $ node -> getOID ( ) ) ; if ( $ nodeCopy == null ) { // if not, create it $ nodeCopy = $ persistenceFacade -> create ( $ node -> getType ( ) ) ; $ node -> copyValues ( $ nodeCopy , false ) ; } // save copy $ this -> registerCopy ( $ node , $ nodeCopy ) ; if ( $ logger -> isInfoEnabled ( ) ) { $ logger -> info ( "Copied: " . $ node -> getOID ( ) . " to " . $ nodeCopy -> getOID ( ) ) ; } if ( $ logger -> isDebugEnabled ( ) ) { $ logger -> debug ( $ nodeCopy -> __toString ( ) ) ; } // create the connections to already copied relatives // this must be done after saving the node in order to have a correct oid $ mapper = $ node -> getMapper ( ) ; $ relations = $ mapper -> getRelations ( ) ; foreach ( $ relations as $ relation ) { if ( $ relation -> getOtherNavigability ( ) ) { $ otherRole = $ relation -> getOtherRole ( ) ; $ relativeValue = $ node -> getValue ( $ otherRole ) ; $ relatives = $ relation -> isMultiValued ( ) ? $ relativeValue : ( $ relativeValue != null ? [ $ relativeValue ] : [ ] ) ; foreach ( $ relatives as $ relative ) { $ copiedRelative = $ this -> getCopy ( $ relative -> getOID ( ) ) ; if ( $ copiedRelative != null ) { $ nodeCopy -> addNode ( $ copiedRelative , $ otherRole ) ; if ( $ logger -> isDebugEnabled ( ) ) { $ logger -> debug ( "Added " . $ copiedRelative -> getOID ( ) . " to " . $ nodeCopy -> getOID ( ) ) ; $ logger -> debug ( $ copiedRelative -> __toString ( ) ) ; } } } } } return $ nodeCopy ; }
Create a copy of the node with the given object id. The returned
node is already persisted.
@param $oid The object id of the node to copy
@return The copied Node or null
Create a copy of the node with the given object id . The returned node is already persisted .