/**
  * as defined by interface: do something with this item.
  * we expect a node, will throw an exception if anything else
  */
 public function visit(ItemInterface $item)
 {
     if (!$item instanceof NodeInterface) {
         throw new \Exception("Internal error: did not expect to visit a non-node object: {$item}");
     }
     $document = $this->odm->find(null, $item->getPath());
     if (!$this->showall && !$document->getVisible()) {
         // ignore hidden entries
         return;
     }
     $url = $this->getUrl($document);
     $this->tree[$url] = $document->getLabel();
     //TODO: this could return the same list of info as menucollectorvisitor, making that one obsolete
 }
 /**
  * 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);
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function isSame(ItemInterface $otherItem)
 {
     $this->checkState();
     if ($this === $otherItem) {
         // trivial case
         return true;
     }
     if ($this->session->getRepository() === $otherItem->getSession()->getRepository() && $this->session->getWorkspace() === $otherItem->getSession()->getWorkspace() && get_class($this) == get_class($otherItem)) {
         if ($this instanceof Node) {
             if ($this->uuid == $otherItem->getIdentifier()) {
                 return true;
             }
             // assert($this instanceof Property)
         } elseif ($this->name == $otherItem->getName() && $this->getParent()->isSame($otherItem->getParent())) {
             return true;
         }
     }
     return false;
 }
Example #5
0
 /**
  * Determine whether this item is to be considered a system item that you
  * usually want to hide and that should not be removed when purging the
  * repository.
  *
  * @param ItemInterface $item
  *
  * @return boolean true if $item is a system item, false otherwise
  */
 public static function isSystemItem(ItemInterface $item)
 {
     if ($item->getDepth() > 1) {
         return false;
     }
     $name = $item->getName();
     return strpos($name, 'jcr:') === 0 || strpos($name, 'rep:') === 0;
 }
 /**
  * Called when the Visitor is passed to an Item.
  *
  * It calls TraversingItemVisitor::entering() followed by
  * TraversingItemVisitor::leaving(). Implement these abstract methods to
  * specify behavior on 'arrival at' and 'after leaving' the $item.
  *
  * If this method throws, the visiting process is aborted.
  *
  * @param ItemInterface $item the Node or Property that is accepting
  *      this visitor.
  *
  * @throws RepositoryException if an error occurs.
  *
  * @api
  */
 public function visit(ItemInterface $item)
 {
     if ($this->currentDepth == 0) {
         $this->currentDepth = $item->getDepth();
     }
     if ($item instanceof PropertyInterface) {
         $this->entering($item, $this->currentDepth);
         $this->leaving($item, $this->currentDepth);
     } else {
         /** @var $item NodeInterface */
         try {
             if ($this->breadthFirst === false) {
                 $this->entering($item, $this->currentDepth);
                 if ($this->maxDepth == -1 || $this->currentDepth < $this->maxDepth) {
                     $this->currentDepth++;
                     foreach ($item->getProperties() as $property) {
                         /** @var $property PropertyInterface */
                         $property->accept($this);
                     }
                     foreach ($item->getNodes() as $node) {
                         /** @var $node NodeInterface */
                         $node->accept($this);
                     }
                     $this->currentDepth--;
                 }
                 $this->leaving($item, $this->currentDepth);
             } else {
                 $this->entering($item, $this->currentDepth);
                 $this->leaving($item, $this->currentDepth);
                 if ($this->maxDepth == -1 || $this->currentDepth < $this->maxDepth) {
                     foreach ($item->getProperties() as $property) {
                         /** @var $property PropertyInterface */
                         $property->accept($this);
                     }
                     foreach ($item->getNodes() as $node) {
                         /** @var $node NodeInterface */
                         $node->accept($this);
                     }
                 }
                 while (!$this->currentQueue->isEmpty() || !$this->nextQueue->isEmpty()) {
                     if ($this->currentQueue->isEmpty()) {
                         $this->currentDepth++;
                         $this->currentQueue = $this->nextQueue;
                         $this->nextQueue = new SplQueue();
                     }
                     $item = $this->currentQueue->dequeue();
                     $item->accept($this);
                 }
                 $this->currentDepth = 0;
             }
         } catch (RepositoryException $exception) {
             $this->currentDepth = 0;
             throw $exception;
         }
     }
 }
Example #7
0
 /**
  * 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;
     }
 }