예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey)
 {
     $value = $property->getValue();
     if ($node->getIdentifier() !== null && $value === $node->getIdentifier()) {
         throw new \InvalidArgumentException('Internal link node cannot reference itself');
     }
     parent::write($node, $property, $userId, $webspaceKey, $languageCode, $segmentKey);
 }
예제 #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
 public function testRestore()
 {
     $session = $this->sessionManager->getSession();
     $rootNode = $session->getNode('/cmf/sulu_io/routes/de');
     // create routes for content
     $this->rlpMapper->save($this->content2, '/news', 'sulu_io', 'de');
     $this->rlpMapper->save($this->content1, '/news/news-1', 'sulu_io', 'de');
     // FIXME  issue: https://github.com/jackalope/jackalope/issues/227
     // FIXME  pr: https://github.com/jackalope/jackalope/pull/228
     //        $this->rlpMapper->save($this->content1, '/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();
     // move route
     $this->rlpMapper->move('/news', '/asdf', 'sulu_io', 'de');
     $session->save();
     $session->refresh(false);
     // move route
     $this->rlpMapper->move('/asdf', '/test', 'sulu_io', 'de');
     $session->save();
     $session->refresh(false);
     // load history
     $result = $this->rlpMapper->loadHistoryByContentUuid($this->content2->getIdentifier(), 'sulu_io', 'de');
     $this->assertEquals(2, count($result));
     $news = $rootNode->getNode('news');
     $news1 = $rootNode->getNode('news/news-1');
     $test = $rootNode->getNode('test');
     $test1 = $rootNode->getNode('test/news-1');
     // before
     $this->assertTrue($news->getPropertyValue('sulu:history'));
     $this->assertEquals($test, $news->getPropertyValue('sulu:content'));
     $this->assertTrue($news1->getPropertyValue('sulu:history'));
     $this->assertEquals($test1, $news1->getPropertyValue('sulu:content'));
     $this->assertFalse($test->getPropertyValue('sulu:history'));
     $this->assertEquals($this->content2, $test->getPropertyValue('sulu:content'));
     $this->assertFalse($test1->getPropertyValue('sulu:history'));
     $this->assertEquals($this->content1, $test1->getPropertyValue('sulu:content'));
     sleep(1);
     $this->rlpMapper->restoreByPath('/news', 'sulu_io', 'de');
     // after
     $this->assertFalse($news->getPropertyValue('sulu:history'));
     $this->assertEquals($this->content2, $news->getPropertyValue('sulu:content'));
     $this->assertTrue($news1->getPropertyValue('sulu:history'));
     $this->assertEquals($test1, $news1->getPropertyValue('sulu:content'));
     $this->assertTrue($test->getPropertyValue('sulu:history'));
     $this->assertEquals($news, $test->getPropertyValue('sulu:content'));
     $this->assertFalse($test1->getPropertyValue('sulu:history'));
     $this->assertEquals($this->content1, $test1->getPropertyValue('sulu:content'));
     // load history
     $result = $this->rlpMapper->loadHistoryByContentUuid($this->content2->getIdentifier(), 'sulu_io', 'de');
     $this->assertEquals(2, count($result));
     $this->assertEquals('/test', $result[0]->getResourceLocator());
     $this->assertTrue($result[0]->getCreated() > $result[1]->getCreated());
     $this->assertEquals('/asdf', $result[1]->getResourceLocator());
 }
 /**
  * Transform a node into a uuid
  *
  * @param \PHPCR\NodeInterface|null $node
  *
  * @return string|null the uuid to the node or null if $node is null
  *
  * @throws UnexpectedTypeException if given value is not a PHPCR\NodeInterface
  */
 public function transform($node)
 {
     if (null === $node) {
         return null;
     }
     if (!$node instanceof NodeInterface) {
         throw new UnexpectedTypeException($node, 'PHPCR\\NodeInterface');
     }
     return $node->getIdentifier();
 }
예제 #5
0
 /**
  * Upgrades the node to new URL representation.
  *
  * @param NodeInterface $node The node to be upgraded
  * @param string $locale The locale of the node to be upgraded
  * @param array $properties The properties which are or contain URL fields
  * @param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise
  */
 private function upgradeNode(NodeInterface $node, $locale, array $properties, $addScheme)
 {
     /** @var BasePageDocument $document */
     $document = $this->documentManager->find($node->getIdentifier(), $locale);
     $documentLocales = $this->documentInspector->getLocales($document);
     if (!in_array($locale, $documentLocales)) {
         return;
     }
     foreach ($properties as $property) {
         $propertyValue = $document->getStructure()->getProperty($property['property']->getName());
         if ($property['property'] instanceof BlockMetadata) {
             $this->upgradeBlockProperty($property['property'], $property['components'], $propertyValue, $addScheme);
         } else {
             $this->upgradeProperty($propertyValue, $addScheme);
         }
     }
     $this->documentManager->persist($document, $locale);
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function loadByNode(NodeInterface $node, $locale, $webspaceKey = null, $excludeGhost = true, $loadGhostContent = false, $excludeShadow = true)
 {
     $document = $this->loadDocument($node->getIdentifier(), $locale, array('load_ghost_content' => $loadGhostContent, 'exclude_ghost' => $excludeGhost, 'exclude_shadow' => $excludeShadow));
     return $this->documentToStructure($document);
 }
예제 #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 NodeInterface $node             The item that is being removed
  * @param bool          $sessionOperation whether the node removal should be
  *      dispatched immediately or needs to be scheduled in the operations log
  *
  * @see ObjectManager::removeItem()
  */
 protected function performNodeRemove($absPath, NodeInterface $node, $sessionOperation = true, $cascading = false)
 {
     if (!$sessionOperation && !$cascading) {
         $this->transport->deleteNodeImmediately($absPath);
     }
     unset($this->objectsByUuid[$node->getIdentifier()]);
     unset($this->objectsByPath['Node'][$absPath]);
     if ($sessionOperation) {
         // keep reference to object in case of refresh
         $operation = new RemoveNodeOperation($absPath, $node);
         $this->nodesRemove[$absPath] = $operation;
         if (!$cascading) {
             $this->operationsLog[] = $operation;
         }
     }
 }
 /**
  * @param SessionInterface $session
  * @param NodeInterface    $node
  *
  * @return bool|string FALSE if not mapped, string if url is mapped
  */
 protected function mapUrl(SessionInterface $session, NodeInterface $node)
 {
     $phpcrClass = $node->getPropertyValue('phpcr:class');
     if (!is_subclass_of($phpcrClass, 'Symfony\\Cmf\\Component\\Routing\\RouteReferrersReadInterface')) {
         return false;
     }
     try {
         $url = $this->router->generate(null, array('content_id' => $node->getIdentifier()));
     } catch (RouteNotFoundException $e) {
         return false;
     }
     return $url;
 }
예제 #9
0
 /**
  * Recursively output node and all its children into the file in the system
  * view format
  *
  * @param NodeInterface $node   the node to output
  * @param resource      $stream The stream resource (i.e. acquired with fopen) to
  *      which the XML serialization of the subgraph will be output. Must
  *      support the fwrite method.
  * @param boolean $skipBinary A boolean governing whether binary properties
  *      are to be serialized.
  * @param boolean $noRecurse A boolean governing whether the subgraph at
  *      absPath is to be recursed.
  * @param boolean $root Whether this is the root node of the resulting
  *      document, meaning the namespace declarations have to be included in
  *      it.
  */
 private static function exportSystemViewRecursive(NodeInterface $node, NamespaceRegistryInterface $ns, $stream, $skipBinary, $noRecurse, $root = false)
 {
     fwrite($stream, '<sv:node');
     if ($root) {
         self::exportNamespaceDeclarations($ns, $stream);
     }
     fwrite($stream, ' sv:name="' . (0 === $node->getDepth() ? 'jcr:root' : htmlspecialchars($node->getName())) . '">');
     // the order MUST be primary type, then mixins, if any, then jcr:uuid if its a referenceable node
     fwrite($stream, '<sv:property sv:name="jcr:primaryType" sv:type="Name"><sv:value>' . htmlspecialchars($node->getPropertyValue('jcr:primaryType')) . '</sv:value></sv:property>');
     if ($node->hasProperty('jcr:mixinTypes')) {
         fwrite($stream, '<sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true">');
         foreach ($node->getPropertyValue('jcr:mixinTypes') as $type) {
             fwrite($stream, '<sv:value>' . htmlspecialchars($type) . '</sv:value>');
         }
         fwrite($stream, '</sv:property>');
     }
     if ($node->isNodeType('mix:referenceable')) {
         fwrite($stream, '<sv:property sv:name="jcr:uuid" sv:type="String"><sv:value>' . $node->getIdentifier() . '</sv:value></sv:property>');
     }
     foreach ($node->getProperties() as $name => $property) {
         /** @var $property \PHPCR\PropertyInterface */
         if ($name == 'jcr:primaryType' || $name == 'jcr:mixinTypes' || $name == 'jcr:uuid') {
             // explicitly handled before
             continue;
         }
         if (PropertyType::BINARY == $property->getType() && $skipBinary) {
             // do not output binary data in the xml
             continue;
         }
         fwrite($stream, '<sv:property sv:name="' . htmlentities($name) . '" sv:type="' . PropertyType::nameFromValue($property->getType()) . '"' . ($property->isMultiple() ? ' sv:multiple="true"' : '') . '>');
         $values = $property->isMultiple() ? $property->getString() : array($property->getString());
         foreach ($values as $value) {
             if (PropertyType::BINARY == $property->getType()) {
                 $val = base64_encode($value);
             } else {
                 $val = htmlspecialchars($value);
                 //TODO: can we still have invalid characters after this? if so base64 and property, xsi:type="xsd:base64Binary"
             }
             fwrite($stream, "<sv:value>{$val}</sv:value>");
         }
         fwrite($stream, "</sv:property>");
     }
     if (!$noRecurse) {
         foreach ($node as $child) {
             if (!($child->getDepth() == 1 && NodeHelper::isSystemItem($child))) {
                 self::exportSystemViewRecursive($child, $ns, $stream, $skipBinary, $noRecurse);
             }
         }
     }
     fwrite($stream, '</sv:node>');
 }
예제 #10
0
 /**
  * Upgrades the node to new date representation.
  *
  * @param NodeInterface $node The node to be upgraded
  * @param string $locale The locale of the node to be upgraded
  * @param array $properties The properties which are or contain date fields
  * @param bool $up
  */
 private function upgradeNode(NodeInterface $node, $locale, array $properties, $up)
 {
     /** @var BasePageDocument $document */
     $document = $this->documentManager->find($node->getIdentifier(), $locale);
     $documentLocales = $this->documentInspector->getLocales($document);
     if (!in_array($locale, $documentLocales)) {
         return;
     }
     foreach ($properties as $property) {
         if ($property['property'] instanceof BlockMetadata) {
             $this->upgradeBlockProperty($property['property'], $property['components'], $node, $locale, $up);
         } else {
             $this->upgradeProperty($property['property'], $node, $locale, $up);
         }
     }
     $this->documentManager->persist($document, $locale, ['auto_name' => false]);
 }
예제 #11
0
파일: InternalLinks.php 프로젝트: sulu/sulu
 /**
  * {@inheritdoc}
  */
 public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey)
 {
     $value = $property->getValue();
     if ($value instanceof ArrayableInterface) {
         $value = $value->toArray();
     }
     if (isset($value)) {
         // remove not existing ids
         $session = $node->getSession();
         $selectedNodes = $session->getNodesByIdentifier($value);
         $ids = [];
         foreach ($selectedNodes as $selectedNode) {
             if ($selectedNode->getIdentifier() === $node->getIdentifier()) {
                 throw new \InvalidArgumentException('You are not allowed to link a page to itself!');
             }
             $ids[] = $selectedNode->getIdentifier();
         }
         $value = $ids;
     }
     // set value to node
     $node->setProperty($property->getName(), $value, PropertyType::REFERENCE);
 }
예제 #12
0
 /**
  * Remove the given property, or the value which references the node (when
  * multi-valued).
  *
  * @param NodeInterface     $node
  * @param PropertyInterface $property
  */
 private function dereferenceProperty(NodeInterface $node, PropertyInterface $property)
 {
     if (false === $property->isMultiple()) {
         $property->remove();
         return;
     }
     // dereference from multi-valued referring properties
     $values = $property->getValue();
     foreach ($values as $i => $referencedNode) {
         if ($referencedNode->getIdentifier() === $node->getIdentifier()) {
             unset($values[$i]);
         }
     }
     $property->getParent()->setProperty($property->getName(), $values);
 }
예제 #13
0
파일: SuluNode.php 프로젝트: sulu/sulu
 /**
  * {@inheritdoc}
  */
 public function getIdentifier()
 {
     return $this->node->getIdentifier();
 }
예제 #14
0
 /**
  * Upgrades the node to new URL representation.
  *
  * @param NodeInterface $node The node to be upgraded
  * @param string $locale The locale of the node to be upgraded
  * @param array $properties The properties which are or contain URL fields
  * @param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise
  */
 private function upgradeNode(NodeInterface $node, $locale, $properties, $addScheme)
 {
     /** @var BasePageDocument $document */
     $document = $this->documentManager->find($node->getIdentifier(), $locale);
     $documentLocales = $this->documentInspector->getLocales($document);
     if (!in_array($locale, $documentLocales)) {
         return;
     }
     foreach ($properties as $property) {
         $this->upgradeProperty($document->getStructure()->getProperty($property), $addScheme);
     }
     $this->documentManager->persist($document, $locale);
 }
 /**
  * Return the document for the given managed node.
  *
  * @param NodeInterface $node
  *
  * @throws \RuntimeException If the node is not managed
  */
 public function getDocumentForNode(NodeInterface $node)
 {
     $identifier = $node->getIdentifier();
     $this->assertNodeExists($identifier);
     return $this->nodeDocumentMap[$identifier];
 }