protected function rewriteItemPaths($curPath, $newPath)
{
// update internal references in parent
$parentCurPath = PathHelper::getParentPath($curPath);
$parentNewPath = PathHelper::getParentPath($newPath);
if (isset($this->objectsByPath['Node'][$parentCurPath])) {
/** @var $node Node */
$node = $this->objectsByPath['Node'][$parentCurPath];
if (!$node->hasNode(PathHelper::getNodeName($curPath))) {
throw new PathNotFoundException("Source path can not be found: {$curPath}");
}
$node->unsetChildNode(PathHelper::getNodeName($curPath), true);
}
if (isset($this->objectsByPath['Node'][$parentNewPath])) {
/** @var $node Node */
$node = $this->objectsByPath['Node'][$parentNewPath];
$node->addChildNode($this->getNodeByPath($curPath), true, PathHelper::getNodeName($newPath));
}
// propagate to current and children items of $curPath, updating internal path
/** @var $node Node */
foreach ($this->objectsByPath['Node'] as $path => $node) {
// is it current or child?
if (strpos($path, $curPath . '/') === 0 || $path == $curPath) {
// curPath = /foo
// newPath = /mo
// path = /foo/bar
// newItemPath= /mo/bar
$newItemPath = substr_replace($path, $newPath, 0, strlen($curPath));
if (isset($this->objectsByPath['Node'][$path])) {
$node = $this->objectsByPath['Node'][$path];
$this->objectsByPath['Node'][$newItemPath] = $node;
unset($this->objectsByPath['Node'][$path]);
$node->setPath($newItemPath, true);
}
// update uuid cache
$this->objectsByUuid[$node->getIdentifier()] = $node->getPath();
}
}
}