Esempio n. 1
0
 public function testGetParentPath()
 {
     $session = $this->sessionManager->getSession();
     $c1 = $this->content1;
     $c2 = $c1->addNode('content2');
     $c2->addMixin('mix:referenceable');
     $session->save();
     $c3 = $c2->addNode('content3');
     $c3->addMixin('mix:referenceable');
     $session->save();
     $c4 = $c3->addNode('content4');
     $c4->addMixin('mix:referenceable');
     $session->save();
     // create routes for content
     $this->rlpMapper->save($c2, '/news', 'sulu_io', 'de');
     $this->rlpMapper->save($c3, '/news/news-1', 'sulu_io', 'de');
     $this->rlpMapper->save($c4, '/news/news-1/sub-1', 'sulu_io', 'de');
     $this->rlpMapper->save($this->content1, '/news/news-1/sub-2', 'sulu_io', 'de');
     $this->rlpMapper->save($this->content1, '/news/news-2', 'sulu_io', 'de');
     $this->rlpMapper->save($this->content1, '/news/news-2/sub-1', 'sulu_io', 'de');
     $this->rlpMapper->save($this->content1, '/news/news-2/sub-2', 'sulu_io', 'de');
     $session->save();
     $result = $this->rlpMapper->getParentPath($c4->getIdentifier(), 'sulu_io', 'de');
     $this->assertEquals('/news/news-1', $result);
     $result = $this->rlpMapper->getParentPath($c4->getIdentifier(), 'sulu_io', 'en');
     $this->assertNull($result);
 }
Esempio n. 2
0
 /**
  * adopts resource locator of children by iteration.
  *
  * @param NodeInterface $contentNode
  * @param int           $userId
  * @param string        $webspaceKey
  * @param string        $languageCode
  * @param bool          $iterate
  * @param string        $segmentKey
  */
 private function adaptResourceLocators(NodeInterface $contentNode, $userId, $webspaceKey, $languageCode, $segmentKey = null, $iterate = true)
 {
     foreach ($contentNode->getNodes() as $node) {
         // determine structure
         $templatePropertyName = $this->nodeHelper->getTranslatedPropertyName('template', $languageCode);
         if (!$node->hasProperty($templatePropertyName)) {
             continue;
         }
         $template = $node->getPropertyValue($templatePropertyName);
         $structure = $this->structureManager->getStructure($template);
         // only if rlp exists
         if ($structure->hasTag('sulu.rlp')) {
             // get rlp
             try {
                 $rlp = $this->loadByContent($node, $webspaceKey, $languageCode);
             } catch (ResourceLocatorNotFoundException $ex) {
                 $contentNode->getSession()->save();
                 $rlpPart = $node->getPropertyValue($this->nodeHelper->getTranslatedPropertyName('title', $languageCode));
                 $prentRlp = $this->mapper->getParentPath($node->getIdentifier(), $webspaceKey, $languageCode, $segmentKey);
                 // generate new resourcelocator
                 $rlp = $this->generate($rlpPart, $prentRlp, $webspaceKey, $languageCode);
             }
             // determine rlp property
             $property = $structure->getPropertyByTagName('sulu.rlp');
             $contentType = $this->contentTypeManager->get($property->getContentTypeName());
             $property->setValue($rlp);
             // write value to node
             $translatedProperty = $this->nodeHelper->getTranslatedProperty($property, $languageCode);
             $contentType->write($node, $translatedProperty, $userId, $webspaceKey, $languageCode, $segmentKey);
         }
         // for node move the tree will be copied to then there is the iteration over this function
         // for node copy the iteration is done by the content-type which calls over the move function
         //     recursively this function
         if ($iterate) {
             $this->adaptResourceLocators($node, $userId, $webspaceKey, $languageCode, $segmentKey);
         }
     }
 }