예제 #1
0
 public function loadFixtures()
 {
     $req = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('en')->setUserId(1)->setData(['title' => 'ElePHPant'])->setState(StructureInterface::STATE_PUBLISHED);
     $this->snippet1 = $this->contentMapper->saveRequest($req);
     $req = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('de')->setUserId(1)->setData(['title' => 'Penguin'])->setState(StructureInterface::STATE_PUBLISHED);
     $this->snippet2 = $this->contentMapper->saveRequest($req);
     $this->snippet1Node = $this->session->getNodeByIdentifier($this->snippet1->getUuid());
     $this->snippet1OriginalPath = $this->snippet1Node->getPath();
     $req = ContentMapperRequest::create()->setUuid($this->snippet1->getUuid())->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('de')->setUserId(1)->setData(['title' => 'English ElePHPant'])->setState(StructureInterface::STATE_PUBLISHED);
     $this->contentMapper->saveRequest($req);
     $req = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('en')->setUserId(1)->setData(['title' => 'Some other animal'])->setState(StructureInterface::STATE_PUBLISHED);
     $this->contentMapper->saveRequest($req);
 }
예제 #2
0
 protected function setUp()
 {
     parent::setUp();
     $this->contentMapper = $this->prophesize('Sulu\\Component\\Content\\Mapper\\ContentMapperInterface');
     $this->requestAnalyzer = $this->prophesize('Sulu\\Component\\Webspace\\Analyzer\\RequestAnalyzerInterface');
     $this->contentTypeManager = $this->prophesize('Sulu\\Component\\Content\\ContentTypeManagerInterface');
     $this->structureManager = $this->prophesize('Sulu\\Component\\Content\\Compat\\StructureManagerInterface');
     $this->sessionManager = $this->prophesize('Sulu\\Component\\PHPCR\\SessionManager\\SessionManagerInterface');
     $this->session = $this->prophesize('PHPCR\\SessionInterface');
     $this->node = $this->prophesize('PHPCR\\NodeInterface');
     $this->parentNode = $this->prophesize('PHPCR\\NodeInterface');
     $this->startPageNode = $this->prophesize('PHPCR\\NodeInterface');
     $webspace = new Webspace();
     $webspace->setKey('sulu_test');
     $locale = new Localization();
     $locale->setCountry('us');
     $locale->setLanguage('en');
     $this->requestAnalyzer->getWebspace()->willReturn($webspace);
     $this->requestAnalyzer->getCurrentLocalization()->willReturn($locale);
     $this->contentTypeManager->get('text_line')->willReturn(new TextLine(''));
     $this->sessionManager->getSession()->willReturn($this->session->reveal());
     $this->sessionManager->getContentNode('sulu_test')->willReturn($this->startPageNode->reveal());
     $this->session->getNodeByIdentifier('123-123-123')->willReturn($this->node->reveal());
     $this->session->getNodeByIdentifier('321-321-321')->willReturn($this->parentNode->reveal());
     $this->node->getIdentifier()->willReturn('123-123-123');
     $this->node->getParent()->willReturn($this->parentNode->reveal());
     $this->node->getDepth()->willReturn(4);
     $this->parentNode->getIdentifier()->willReturn('321-321-321');
     $this->parentNode->getDepth()->willReturn(3);
     $this->startPageNode->getDepth()->willReturn(3);
     $this->structureResolver = new StructureResolver($this->contentTypeManager->reveal(), $this->structureManager->reveal());
 }
예제 #3
0
 /**
  * {@inheritDoc}
  */
 public function findTranslation($className, $id, $locale, $fallback = true)
 {
     try {
         if (UUIDHelper::isUUID($id)) {
             try {
                 $id = $this->session->getNodeByIdentifier($id)->getPath();
             } catch (ItemNotFoundException $e) {
                 return null;
             }
         } elseif (strpos($id, '/') !== 0) {
             $id = '/' . $id;
         }
         $document = $this->unitOfWork->getDocumentById($id);
         if ($document) {
             $this->unitOfWork->validateClassName($document, $className);
             $class = $this->getClassMetadata(get_class($document));
             $this->unitOfWork->doLoadTranslation($document, $class, $locale, $fallback);
             return $document;
         }
         $node = $this->session->getNode($id);
     } catch (PathNotFoundException $e) {
         return null;
     }
     $hints = array('locale' => $locale, 'fallback' => $fallback);
     return $this->unitOfWork->getOrCreateDocument($className, $node, $hints);
 }
예제 #4
0
 /**
  * Normalize the given path or ID to a path.
  *
  * @param string $identifier
  *
  * @return string
  */
 private function normalizeToPath($identifier)
 {
     if (UUIDHelper::isUUID($identifier)) {
         $identifier = $this->session->getNodeByIdentifier($identifier)->getPath();
     }
     return $identifier;
 }
예제 #5
0
 /**
  * Load the document from the content repository in the given language.
  * If $fallback is set to true, then the language chooser strategy is used to load the best suited
  * language for the translatable fields.
  *
  * If no translations can be found either using the fallback mechanism or not, an error is thrown.
  *
  * Note that this will be the same object as you got with a previous find/findTranslation call - we can't
  * allow copies of objects to exist
  *
  * @param $className
  * @param $id
  * @param $locale The language to try to load
  * @param bool $fallback Set to true if the language fallback mechanism should be used
  * @return object
  */
 public function findTranslation($className, $id, $locale, $fallback = true)
 {
     try {
         $node = UUIDHelper::isUUID($id) ? $this->session->getNodeByIdentifier($id) : $this->session->getNode($id);
     } catch (\PHPCR\PathNotFoundException $e) {
         return null;
     }
     $hints = array('locale' => $locale, 'fallback' => $fallback);
     return $this->unitOfWork->createDocument($className, $node, $hints);
 }
예제 #6
0
 /**
  * @param ObjectEvent $event
  */
 public function onPostDeserialize(ObjectEvent $event)
 {
     $document = $event->getObject();
     if (!$document instanceof PageDocument) {
         return;
     }
     if (!$document->getUuid()) {
         return;
     }
     try {
         $node = $this->session->getNodeByIdentifier($document->getUuid());
     } catch (ItemNotFoundException $e) {
         return;
     }
     if ($this->registry->hasNode($node)) {
         $registeredDocument = $this->registry->getDocumentForNode($node);
         $this->registry->deregisterDocument($registeredDocument);
     }
     // TODO use the original locale somehow
     $this->registry->registerDocument($document, $node, $document->getLocale());
 }
예제 #7
0
 public function testFindWithInternalLinkToItself()
 {
     $this->initPhpcr();
     $link = $this->createPage('test-1', 'de');
     $page = $this->createInternalLinkPage('test-2', 'de', $link);
     $node = $this->session->getNodeByIdentifier($page->getUuid());
     $node->setProperty('i18n:de-internal_link', $node);
     $this->session->save();
     // should load content with requested node and not try to follow internal link
     $result = $this->contentRepository->find($page->getUuid(), 'de', 'sulu_io', MappingBuilder::create()->addProperties(['title'])->getMapping());
     $this->assertEquals($page->getUuid(), $result->getId());
     $this->assertEquals('/test-2', $result->getPath());
     $this->assertEquals('test-2', $result['title']);
 }
예제 #8
0
    private function migrateInternalLinks(SessionInterface $session, $directionUp = true)
    {
        $workspace = $session->getWorkspace();
        $queryManager = $workspace->getQueryManager();
        $webspaceManager = $this->container->get('sulu_core.webspace.webspace_manager');
        $propertyEncoder = $this->container->get('sulu_document_manager.property_encoder');
        $webspaces = $webspaceManager->getWebspaceCollection();
        foreach ($webspaces as $webspace) {
            foreach ($webspace->getAllLocalizations() as $localization) {
                $locale = $localization->getLocalization();
                $sql = <<<EOT
SELECT * FROM [nt:unstructured] WHERE %s = 2
EOT;
                $query = $queryManager->createQuery(sprintf($sql, '[' . $propertyEncoder->localizedSystemName('nodeType', $locale) . ']'), 'JCR-SQL2');
                $rows = $query->execute();
                foreach ($rows as $row) {
                    $node = $row->getNode();
                    $internalLinkName = $propertyEncoder->localizedSystemName('internal_link', $locale);
                    try {
                        if (true === $directionUp) {
                            $internalUuid = $node->getPropertyValue($internalLinkName);
                            $internalNode = $session->getNodeByIdentifier($internalUuid);
                            $node->setProperty($internalLinkName, null);
                            $node->setProperty($internalLinkName, $internalNode);
                        } else {
                            $internalNode = $node->getPropertyValue($internalLinkName);
                            $internalNodeUuid = $internalNode->getIdentifier();
                            $node->setProperty($internalLinkName, null);
                            $node->setProperty($internalLinkName, $internalNodeUuid);
                        }
                    } catch (\Exception $e) {
                        echo $e->getMessage() . PHP_EOL;
                    }
                }
            }
        }
    }
예제 #9
0
 /**
  * @see \PHPCR\SessionInterface::getNodeByIdentifier
  */
 public function getNodeByIdentifier($id)
 {
     $node = $this->session->getNodeByIdentifier($id);
     return new Node($node);
 }