/** * Print information about the visited node. * * @param ItemInterface $item the node to visit */ public function visit(ItemInterface $item) { if (!$item instanceof NodeInterface) { throw new \Exception("Internal error: did not expect to visit a non-node object: {$item}"); } if ($item->getDepth() == 0) { $name = 'ROOT'; } elseif ($this->showFullPath) { $name = $item->getPath(); } else { $name = $item->getName(); } $out = str_repeat(' ', $this->level) . '<comment>' . $name . '</comment>'; if ($this->identifiers) { $identifier = $item->getIdentifier(); if ($identifier) { $out .= "({$identifier})"; } } $out .= ':'; $this->output->writeln($out); }
/** * WRITE: add an item at the specified path. * * @param string $absPath the path to the node, including the node identifier * @param \PHPCR\ItemInterface $item The item to add. * * @throws \PHPCR\ItemExistsException if a node already exists at that path */ public function addItem($absPath, \PHPCR\ItemInterface $item) { if (isset($this->objectsByPath['Node'][$absPath])) { throw new \PHPCR\ItemExistsException($absPath); //FIXME: same-name-siblings... } $this->objectsByPath['Node'][$absPath] = $item; if ($item instanceof \PHPCR\NodeInterface) { //TODO: determine if we have an identifier. $this->objectsByUuid[$item->getIdentifier()] = $absPath; } $this->itemsAdd[$absPath] = 1; }
/** * Remove the item at absPath from local cache and keep information for undo. * * @param string $absPath The absolute path of the item that is being * removed. Note that contrary to removeItem(), this path is the full * path for a property too. * @param ItemInterface $item The item that is being removed * @param bool $sessionBased i.e. removing a version is dispatched * immediately, don't track for eventual refresh * * @return void * * @see ObjectManager::removeItem() */ protected function performRemove($absPath, ItemInterface $item, $sessionOperation = true) { // was any parent moved? foreach ($this->nodesMove as $dst) { if (strpos($dst, $absPath) === 0) { // this is MOVE, then DELETE but we dispatch DELETE before MOVE // TODO we might could just remove the MOVE and put a DELETE on the previous node :) throw new RepositoryException('Internal error: Deleting (' . $absPath . ') will fail because your move is dispatched to the server after the delete'); } } if ($item instanceof Node) { unset($this->objectsByUuid[$item->getIdentifier()]); } unset($this->objectsByPath['Node'][$absPath]); if (isset($this->itemsAdd[$absPath])) { //this is a new unsaved node unset($this->itemsAdd[$absPath]); } elseif ($sessionOperation) { // keep reference to object in case of refresh // the topmost item delete will be sent to backend and cascade delete $this->itemsRemove[$absPath] = $item; } }