Ejemplo n.º 1
0
 /**
  * @param FindEvent $event
  *
  * @throws DocumentManagerException
  * @throws DocumentNotFoundException
  */
 public function handleFind(FindEvent $event)
 {
     $options = $event->getOptions();
     $aliasOrClass = $options['type'];
     $node = $this->nodeManager->find($event->getId());
     $hydrateEvent = new HydrateEvent($node, $event->getLocale(), $options);
     $this->eventDispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
     $document = $hydrateEvent->getDocument();
     if ($aliasOrClass) {
         $this->checkAliasOrClass($aliasOrClass, $document);
     }
     $event->setDocument($hydrateEvent->getDocument());
 }
 private function resolveParent($parentPath, array $options)
 {
     $autoCreate = $options['auto_create'];
     if ($autoCreate) {
         return $this->nodeManager->createPath($parentPath);
     }
     return $this->nodeManager->find($parentPath);
 }
 private function resolveSiblingName($siblingId, NodeInterface $parentNode, NodeInterface $node)
 {
     if (null === $siblingId) {
         return;
     }
     $siblingPath = $siblingId;
     if (UUIDHelper::isUUID($siblingId)) {
         $siblingPath = $this->nodeManager->find($siblingId)->getPath();
     }
     if ($siblingPath !== null && PathHelper::getParentPath($siblingPath) !== $parentNode->getPath()) {
         throw new DocumentManagerException(sprintf('Cannot reorder documents which are not siblings. Trying to reorder "%s" to "%s"', $node->getPath(), $siblingPath));
     }
     if (null !== $siblingPath) {
         return PathHelper::getNodeName($siblingPath);
     }
     return $node->getName();
 }
 /**
  * Resolve the destination name on move and copy events.
  *
  * @param MoveEvent $event
  */
 private function handleMoveCopy(MoveEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof AutoNameBehavior) {
         return;
     }
     $destId = $event->getDestId();
     $node = $this->registry->getNodeForDocument($document);
     $destNode = $this->nodeManager->find($destId);
     $nodeName = $this->resolver->resolveName($destNode, $node->getName());
     $event->setDestName($nodeName);
 }
Ejemplo n.º 5
0
 /**
  * @param ObjectEvent $event
  */
 public function onPostDeserialize(ObjectEvent $event)
 {
     $document = $event->getObject();
     // only register documents
     if (!$this->metadataFactory->hasMetadataForClass(get_class($document))) {
         return;
     }
     if (!$document->getUuid()) {
         return;
     }
     try {
         $node = $this->nodeManager->find($document->getUuid());
     } catch (DocumentNotFoundException $e) {
         return;
     }
     if ($this->registry->hasNode($node, $document->getLocale())) {
         $registeredDocument = $this->registry->getDocumentForNode($node, $document->getLocale());
         $this->registry->deregisterDocument($registeredDocument);
     }
     // TODO use the original locale somehow
     if (!$this->registry->hasDocument($document)) {
         $this->registry->registerDocument($document, $node, $document->getLocale());
     }
 }