Jackalope\ObjectManager::moveNode PHP Method

moveNode() public method

WRITE: move node from source path to destination path
See also: Session::move()
public moveNode ( string $srcAbsPath, string $destAbsPath )
$srcAbsPath string Absolute path to the source node.
$destAbsPath string Absolute path to the destination where the node shall be moved to.
    public function moveNode($srcAbsPath, $destAbsPath)
    {
        if (!$this->transport instanceof WritingInterface) {
            throw new UnsupportedRepositoryOperationException('Transport does not support writing');
        }
        $srcAbsPath = PathHelper::normalizePath($srcAbsPath);
        $destAbsPath = PathHelper::normalizePath($destAbsPath, true);
        $this->rewriteItemPaths($srcAbsPath, $destAbsPath, true);
        // record every single move in case we have intermediary operations
        $operation = new MoveNodeOperation($srcAbsPath, $destAbsPath);
        $this->operationsLog[] = $operation;
        // update local cache state information
        if ($original = $this->getMoveSrcPath($srcAbsPath)) {
            $srcAbsPath = $original;
        }
        $this->nodesMove[$srcAbsPath] = $operation;
    }

Usage Example

Example #1
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function move($srcAbsPath, $destAbsPath)
 {
     try {
         $parent = $this->objectManager->getNodeByPath(PathHelper::getParentPath($destAbsPath));
     } catch (ItemNotFoundException $e) {
         throw new PathNotFoundException("Target path can not be found: {$destAbsPath}", $e->getCode(), $e);
     }
     if ($parent->hasNode(PathHelper::getNodeName($destAbsPath))) {
         // TODO same-name siblings
         throw new ItemExistsException('Target node already exists at ' . $destAbsPath);
     }
     if ($parent->hasProperty(PathHelper::getNodeName($destAbsPath))) {
         throw new ItemExistsException('Target property already exists at ' . $destAbsPath);
     }
     $this->objectManager->moveNode($srcAbsPath, $destAbsPath);
 }