예제 #1
0
 /**
  * Create a new proxy object from the given document for
  * the given target node.
  *
  * TODO: We only pass the document here in order to correctly evaluate its locale
  *       later. I wonder if it necessary.
  *
  * @param object $fromDocument
  * @param NodeInterface $targetNode
  *
  * @return \ProxyManager\Proxy\GhostObjectInterface
  */
 public function createProxyForNode($fromDocument, NodeInterface $targetNode)
 {
     $eventDispatcher = $this->dispatcher;
     $registry = $this->registry;
     $targetMetadata = $this->metadataFactory->getMetadataForPhpcrNode($targetNode);
     // if node is already registered then just return the registered document
     if ($this->registry->hasNode($targetNode)) {
         $document = $this->registry->getDocumentForNode($targetNode);
         $locale = $registry->getOriginalLocaleForDocument($fromDocument);
         // If the parent is not loaded in the correct locale, reload it in the correct locale.
         if ($registry->getOriginalLocaleForDocument($document) !== $locale) {
             $hydrateEvent = new HydrateEvent($targetNode, $locale);
             $hydrateEvent->setDocument($document);
             $this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
         }
         return $document;
     }
     $initializer = function (LazyLoadingInterface $document, $method, array $parameters, &$initializer) use($fromDocument, $targetNode, $eventDispatcher, $registry) {
         $locale = $registry->getOriginalLocaleForDocument($fromDocument);
         $hydrateEvent = new HydrateEvent($targetNode, $locale);
         $hydrateEvent->setDocument($document);
         $eventDispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
         $initializer = null;
     };
     $proxy = $this->proxyFactory->createProxy($targetMetadata->getClass(), $initializer);
     $locale = $registry->getOriginalLocaleForDocument($fromDocument);
     $this->registry->registerDocument($proxy, $targetNode, $locale);
     return $proxy;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function resolveMetadataForNode(NodeInterface $node)
 {
     if (false === $node->hasProperty('jcr:mixinTypes')) {
         return;
     }
     $mixinTypes = (array) $node->getPropertyValue('jcr:mixinTypes');
     foreach ($mixinTypes as $mixinType) {
         if (true == $this->metadataFactory->hasMetadataForPhpcrType($mixinType)) {
             return $this->metadataFactory->getMetadataForPhpcrType($mixinType);
         }
     }
     return;
 }
 /**
  * It should set the parent document.
  */
 public function testSetParentDocument()
 {
     $this->persistEvent->getDocument()->willReturn($this->document->reveal());
     $this->persistEvent->getLocale()->willReturn('fr');
     $this->metadataFactory->getMetadataForClass(get_class($this->document->reveal()))->willReturn($this->metadata->reveal());
     $this->metadata->getAlias()->willReturn('test');
     $this->nodeManager->createPath('/')->willReturn($this->parentNode->reveal());
     $this->persistEvent->hasParentNode()->shouldBeCalled();
     $this->persistEvent->setParentNode($this->parentNode->reveal())->shouldBeCalled();
     $this->documentManager->find('/test', 'fr')->willReturn($this->parentDocument);
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }
예제 #4
0
 /**
  * @param $node
  */
 private function removeReferencesForNode(NodeInterface $node)
 {
     $references = $node->getReferences();
     foreach ($references as $reference) {
         $referrer = $reference->getParent();
         $metadata = $this->metadataFactory->getMetadataForPhpcrNode($referrer);
         if ($metadata->getClass() === RouteDocument::class) {
             continue;
         }
         $this->dereferenceProperty($node, $reference);
     }
 }
 private function checkAliasOrClass($aliasOrClass, $document)
 {
     if ($this->metadataFactory->hasAlias($aliasOrClass)) {
         $class = $this->metadataFactory->getMetadataForAlias($aliasOrClass)->getClass();
     } elseif (!class_exists($aliasOrClass)) {
         throw new DocumentManagerException(sprintf('Unknown class specified and no alias exists for "%s", known aliases: "%s"', $aliasOrClass, implode('", "', $this->metadataFactory->getAliases())));
     } else {
         $class = $aliasOrClass;
     }
     if (get_class($document) !== $class) {
         throw new DocumentNotFoundException(sprintf('Requested document of type "%s" but got document of type "%s"', $aliasOrClass, get_class($document)));
     }
 }
예제 #6
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());
     }
 }
예제 #7
0
 /**
  * Bind data array to given document.
  *
  * TODO this logic have to be extracted in a proper way.
  *
  * @param CustomUrlDocument $document
  * @param array $data
  * @param string $locale
  */
 private function bind(CustomUrlDocument $document, $data, $locale)
 {
     $document->setTitle($data['title']);
     unset($data['title']);
     $metadata = $this->metadataFactory->getMetadataForAlias('custom_url');
     $accessor = PropertyAccess::createPropertyAccessor();
     foreach ($metadata->getFieldMappings() as $fieldName => $mapping) {
         if (!array_key_exists($fieldName, $data)) {
             continue;
         }
         $value = $data[$fieldName];
         if (array_key_exists('type', $mapping) && $mapping['type'] === 'reference') {
             $value = $this->documentManager->find($value['uuid'], $locale, ['load_ghost_content' => true]);
         }
         $accessor->setValue($document, $fieldName, $value);
     }
     $document->setLocale($locale);
 }
예제 #8
0
 private function upgradeNode(NodeInterface $node, Webspace $webspace, Localization $localization, OutputInterface $output, $depth = 0)
 {
     $locale = $localization->getLocale();
     $localizedTemplatePropertyName = $this->propertyEncoder->localizedSystemName('template', $locale);
     if (!$node->hasProperty($localizedTemplatePropertyName)) {
         return;
     }
     $structureMetadata = $this->structureMetadataFactory->getStructureMetadata($this->metadataFactory->getMetadataForPhpcrNode($node)->getAlias(), $node->getPropertyValue($localizedTemplatePropertyName));
     $property = $structureMetadata->getPropertyByTagName('sulu.rlp');
     if (!$property) {
         return;
     }
     $nodeType = $node->getPropertyValue($this->propertyEncoder->localizedSystemName('nodeType', $locale));
     if ($property->getContentTypeName() !== 'resource_locator' && $nodeType !== Structure::NODE_TYPE_CONTENT) {
         return;
     }
     $baseRoutePath = $this->sessionManager->getRoutePath($webspace->getKey(), $localization->getLocale());
     foreach ($node->getReferences('sulu:content') as $routeProperty) {
         if (strpos($routeProperty->getPath(), $baseRoutePath) !== 0) {
             continue;
         }
         $routeNode = $routeProperty->getParent();
         if ($routeNode->getPropertyValue('sulu:history') === true) {
             continue;
         }
         $resourceLocator = substr($routeNode->getPath(), strlen($baseRoutePath));
         if ($resourceLocator) {
             // only set if resource locator is not empty
             // if the resource locator is empty it is the homepage, whose url should not be changed
             $node->setProperty($this->propertyEncoder->localizedContentName($property->getName(), $locale), $resourceLocator);
             $prefix = '   ';
             for ($i = 0; $i < $depth; ++$i) {
                 $prefix .= '-';
             }
             $title = $node->getPropertyValue($this->propertyEncoder->localizedContentName('title', $locale));
             $output->writeln($prefix . '> "' . $title . '": ' . $resourceLocator);
         }
         break;
     }
 }
 /**
  * @param $document
  *
  * @return string
  */
 protected function getParentName($document)
 {
     return $this->metadataFactory->getMetadataForClass(get_class($document))->getAlias();
 }
예제 #10
0
 private function getQuery($classFqn)
 {
     $metadata = $this->metadataFactory->getMetadataForClass($classFqn);
     // TODO: Use the document manager query builder.
     return $this->documentManager->createQuery(sprintf('SELECT * FROM [nt:unstructured] AS a WHERE [jcr:mixinTypes] = "%s"', $metadata->getPhpcrType()));
 }
 /**
  * Instantiate a new document. The class is determined from
  * the mixins present in the PHPCR node for legacy reasons.
  *
  * @param NodeInterface $node
  *
  * @return object
  */
 private function getDocumentFromNode(NodeInterface $node)
 {
     $metadata = $this->metadataFactory->getMetadataForPhpcrNode($node);
     return $this->instantiateFromMetadata($metadata);
 }
 /**
  * {@inheritdoc}
  */
 public function getAliases()
 {
     return $this->metadataFactory->getAliases();
 }