getContentNode() public method

Returns the content node for given webspace.
Deprecation: Do not use anymore, because the node is always returned from the default session, although multiple sessions can exist
public getContentNode ( string $webspaceKey ) : PHPCR\NodeInterface
$webspaceKey string
return PHPCR\NodeInterface
Esempio n. 1
0
 public function __construct(WebspaceManagerInterface $webspaceManager, SecurityCheckerInterface $securityChecker, SessionManagerInterface $sessionManager, $title)
 {
     $this->webspaceManager = $webspaceManager;
     $this->securityChecker = $securityChecker;
     $this->sessionManager = $sessionManager;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.webspaces');
     $section->setPosition(10);
     $rootNavigationItem->addChild($section);
     $position = 10;
     /** @var Webspace $webspace */
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         if ($this->securityChecker->hasPermission(self::SECURITY_CONTEXT_PREFIX . $webspace->getKey(), PermissionTypes::VIEW)) {
             $webspaceItem = new NavigationItem($webspace->getName());
             $webspaceItem->setPosition($position++);
             $webspaceItem->setIcon('bullseye');
             $indexUuid = $this->sessionManager->getContentNode($webspace->getKey())->getIdentifier();
             $indexPageItem = new NavigationItem('navigation.webspaces.index-page');
             $indexPageItem->setPosition(10);
             $indexPageItem->setAction('content/contents/' . $webspace->getKey() . '/edit:' . $indexUuid . '/content');
             $webspaceItem->addChild($indexPageItem);
             $contentItem = new NavigationItem('navigation.webspaces.content');
             $contentItem->setPosition(20);
             $contentItem->setAction('content/contents/' . $webspace->getKey());
             $webspaceItem->addChild($contentItem);
             $webspaceSettingsItem = new NavigationItem('navigation.webspaces.settings');
             $webspaceSettingsItem->setPosition(30);
             $webspaceSettingsItem->setAction(sprintf('content/webspace/settings:%s/general', $webspace->getKey()));
             $webspaceItem->addChild($webspaceSettingsItem);
             $section->addChild($webspaceItem);
         }
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 2
0
 public function __construct(WebspaceManagerInterface $webspaceManager, SecurityCheckerInterface $securityChecker, SessionManagerInterface $sessionManager, $title)
 {
     $this->webspaceManager = $webspaceManager;
     $this->securityChecker = $securityChecker;
     $this->sessionManager = $sessionManager;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.webspaces');
     $rootNavigationItem->addChild($section);
     /** @var Webspace $webspace */
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         if ($this->securityChecker->hasPermission(self::SECURITY_CONTEXT_PREFIX . $webspace->getKey(), 'view')) {
             $webspaceItem = new NavigationItem($webspace->getName());
             $webspaceItem->setIcon('bullseye');
             $indexUuid = $this->sessionManager->getContentNode($webspace->getKey())->getIdentifier();
             $indexPageItem = new NavigationItem('navigation.webspaces.index-page');
             $indexPageItem->setAction('content/contents/' . $webspace->getKey() . '/edit:' . $indexUuid . '/details');
             $webspaceItem->addChild($indexPageItem);
             $contentItem = new NavigationItem('navigation.webspaces.content');
             $contentItem->setAction('content/contents/' . $webspace->getKey());
             $webspaceItem->addChild($contentItem);
             $section->addChild($webspaceItem);
         }
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $webspaceCollection = $this->webspaceManager->getWebspaceCollection();
     foreach ($webspaceCollection as $webspace) {
         $contentNode = $this->sessionManager->getContentNode($webspace->getKey());
         $this->traverse($contentNode);
         $this->sessionManager->getSession()->save();
     }
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function loadParent($uuid)
 {
     $session = $this->sessionManager->getSession();
     $contentsNode = $this->sessionManager->getContentNode($this->requestAnalyzer->getWebspace()->getKey());
     $node = $session->getNodeByIdentifier($uuid);
     if ($node->getDepth() <= $contentsNode->getDepth()) {
         throw new ParentNotFoundException($uuid);
     }
     return $this->load($node->getParent()->getIdentifier());
 }
 private function initHistory($webspaceKey, $locale)
 {
     $this->initPhpcr();
     $contentNode = $this->sessionManager->getContentNode($webspaceKey);
     $this->phpcrStrategy->save($contentNode, '/team', 1, $webspaceKey, $locale);
     $this->phpcrStrategy->save($contentNode, '/team/daniel', 1, $webspaceKey, $locale);
     $this->phpcrStrategy->save($contentNode, '/team/johannes', 1, $webspaceKey, $locale);
     $this->phpcrStrategy->save($contentNode, '/about-us', 1, $webspaceKey, $locale);
     $this->phpcrStrategy->move('/team', '/my-test', $contentNode, 1, $webspaceKey, $locale);
     $session = $this->sessionManager->getSession();
     $session->save();
     $session->refresh(false);
 }
 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());
 }
 public function testOrderByOrder()
 {
     $root = $this->sessionManager->getContentNode('sulu_io');
     list($nodes) = $this->orderByProvider();
     $session = $this->sessionManager->getSession();
     $node = $session->getNodeByIdentifier($nodes['/qwertz']->getUuid());
     $node->setProperty('sulu:order', 10);
     $node = $session->getNodeByIdentifier($nodes['/asdf']->getUuid());
     $node->setProperty('sulu:order', 20);
     $node = $session->getNodeByIdentifier($nodes['/asdf-1']->getUuid());
     $node->setProperty('sulu:order', 30);
     $node = $session->getNodeByIdentifier($nodes['/qwertz-1']->getUuid());
     $node->setProperty('sulu:order', 40);
     $session->save();
     $session->refresh(false);
     $builder = new SmartContentQueryBuilder($this->structureManager, $this->webspaceManager, $this->sessionManager, $this->languageNamespace);
     // order by default
     $builder->init(['config' => ['dataSource' => $root->getIdentifier(), 'orderBy' => [], 'sortMethod' => 'asc']]);
     $result = $this->contentQuery->execute('sulu_io', ['en'], $builder);
     $this->assertEquals('qwertz', $result[0]['title']);
     $this->assertEquals('asdf', $result[1]['title']);
     $this->assertEquals('ASDF', $result[2]['title']);
     $this->assertEquals('QWERTZ', $result[3]['title']);
     // order by default
     $builder->init(['config' => ['dataSource' => $root->getIdentifier(), 'orderBy' => [], 'sortMethod' => 'desc']]);
     $result = $this->contentQuery->execute('sulu_io', ['en'], $builder);
     $this->assertEquals('QWERTZ', $result[0]['title']);
     $this->assertEquals('ASDF', $result[1]['title']);
     $this->assertEquals('asdf', $result[2]['title']);
     $this->assertEquals('qwertz', $result[3]['title']);
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function getNavigation($parent, $webspaceKey, $locale, $depth = 1, $flat = false, $context = null, $loadExcerpt = false)
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('NavigationMapper::getNavigation');
     }
     $rootDepth = substr_count($this->sessionManager->getContentNode($webspaceKey)->getPath(), '/');
     $parent = $this->sessionManager->getSession()->getNodeByIdentifier($parent)->getPath();
     $depth = $depth + substr_count($parent, '/') - $rootDepth;
     $this->queryBuilder->init(['context' => $context, 'parent' => $parent, 'excerpt' => $loadExcerpt]);
     $result = $this->contentQuery->execute($webspaceKey, [$locale], $this->queryBuilder, $flat, $depth);
     foreach ($result as $item) {
         if (!isset($item['children'])) {
             $item['children'] = [];
         }
     }
     if ($this->stopwatch) {
         $this->stopwatch->stop('NavigationMapper::getNavigation');
     }
     return $result;
 }
Esempio n. 9
0
 /**
  * build datasource where clause.
  */
 private function buildDatasourceWhere()
 {
     $dataSource = $this->getConfig('dataSource');
     $includeSubFolders = $this->getConfig('includeSubFolders', false);
     $sqlFunction = $includeSubFolders !== false && $includeSubFolders !== 'false' ? 'ISDESCENDANTNODE' : 'ISCHILDNODE';
     if ($this->webspaceManager->findWebspaceByKey($dataSource) !== null) {
         $node = $this->sessionManager->getContentNode($dataSource);
     } else {
         $node = $this->sessionManager->getSession()->getNodeByIdentifier($dataSource);
     }
     return $sqlFunction . '(page, \'' . $node->getPath() . '\')';
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function getNodesTree($uuid, $webspaceKey, $languageCode, $excludeGhosts = false, $appendWebspaceNode = false)
 {
     $nodes = $this->loadNodeAndAncestors($uuid, $webspaceKey, $languageCode, $excludeGhosts, true);
     if ($appendWebspaceNode) {
         $webspace = $this->webspaceManager->getWebspaceCollection()->getWebspace($webspaceKey);
         $result = ['_embedded' => ['nodes' => [['id' => $this->sessionManager->getContentNode($webspace->getKey())->getIdentifier(), 'path' => '/', 'title' => $webspace->getName(), 'publishedState' => true, 'hasSub' => true, '_embedded' => ['nodes' => $nodes], '_links' => ['children' => ['href' => $this->apiBasePath . '?depth=1&webspace=' . $webspaceKey . '&language=' . $languageCode . ($excludeGhosts === true ? '&exclude-ghosts=true' : '')]]]]]];
     } else {
         $result = ['_embedded' => ['nodes' => $nodes]];
     }
     // add api links
     $result['_links'] = ['self' => ['href' => $this->apiBasePath . '/tree?uuid=' . $uuid . '&webspace=' . $webspaceKey . '&language=' . $languageCode . ($excludeGhosts === true ? '&exclude-ghosts=true' : '') . ($appendWebspaceNode === true ? '&webspace-node=true' : '')]];
     return $result;
 }
Esempio n. 11
0
 public function testOverride()
 {
     $property = new Property('url', [], 'resource_locator');
     $property->setValue('/test');
     $node = $this->sessionManager->getContentNode('sulu_io')->addNode('test');
     $node->addMixin('sulu:content');
     $this->session->save();
     $this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en');
     $this->assertEquals('/test', $node->getPropertyValue('url'));
     $this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test'));
     $property->setValue('/test-2');
     $this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en');
     $this->assertEquals('/test-2', $node->getPropertyValue('url'));
     $this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test-2'));
 }
Esempio n. 12
0
 public function testFindByPaths()
 {
     $this->initPhpcr();
     $page1 = $this->createPage('test-1', 'de');
     $page11 = $this->createPage('test-1/test-1', 'de', [], $page1);
     $page2 = $this->createPage('test-2', 'de');
     $page3 = $this->createPage('test-3', 'de');
     $result = $this->contentRepository->findByPaths(['/cmf/sulu_io/contents', '/cmf/sulu_io/contents/test-1', '/cmf/sulu_io/contents/test-2'], 'de', MappingBuilder::create()->addProperties(['title'])->getMapping());
     $this->assertCount(3, $result);
     $this->assertEquals($this->sessionManager->getContentNode('sulu_io')->getIdentifier(), $result[0]->getId());
     $this->assertTrue($result[0]->hasChildren());
     $this->assertEmpty($result[0]->getChildren());
     $this->assertEquals($page1->getUuid(), $result[1]->getId());
     $this->assertTrue($result[1]->hasChildren());
     $this->assertEmpty($result[1]->getChildren());
     $this->assertEquals($page2->getUuid(), $result[2]->getId());
     $this->assertFalse($result[2]->hasChildren());
     $this->assertEmpty($result[2]->getChildren());
 }
Esempio n. 13
0
 public function testGetTreeActionAllWebspaceNodes()
 {
     $this->initPhpcr();
     $this->createWebspaceRoot('test_io');
     $page1 = $this->createPage('test-1', 'de');
     $page2 = $this->createPage('test-2', 'de');
     $page11 = $this->createPage('test-1-1', 'de', [], $page1);
     $this->createPage('test-1-1-1', 'de', [], $page11);
     $this->createPage('my-test', 'de', [], null, [], '/cmf/test_io/contents/my-test');
     $client = $this->createAuthenticatedClient();
     $client->request('GET', '/api/nodes/' . $page1->getUuid(), ['tree' => 'true', 'webspace' => 'sulu_io', 'language' => 'de', 'webspace-nodes' => 'all', 'fields' => 'title']);
     $result = json_decode($client->getResponse()->getContent(), true);
     $layer = $result['_embedded']['nodes'];
     $this->assertCount(2, $layer);
     $this->assertEquals($this->sessionManager->getContentNode('sulu_io')->getIdentifier(), $layer[0]['id']);
     $this->assertEquals('Sulu CMF', $layer[0]['title']);
     $this->assertTrue($layer[0]['hasChildren']);
     $this->assertCount(2, $layer[0]['_embedded']['nodes']);
     $this->assertEquals($this->sessionManager->getContentNode('test_io')->getIdentifier(), $layer[1]['id']);
     $this->assertEquals('Test CMF', $layer[1]['title']);
     $this->assertTrue($layer[1]['hasChildren']);
     $this->assertCount(0, $layer[1]['_embedded']['nodes']);
     $layer = $layer[0]['_embedded']['nodes'];
     $this->assertCount(2, $layer);
     $this->assertEquals($page1->getUuid(), $layer[0]['id']);
     $this->assertEquals('test-1', $layer[0]['title']);
     $this->assertTrue($layer[0]['hasChildren']);
     $this->assertCount(1, $layer[0]['_embedded']['nodes']);
     $this->assertEquals($page2->getUuid(), $layer[1]['id']);
     $this->assertEquals('test-2', $layer[1]['title']);
     $this->assertFalse($layer[1]['hasChildren']);
     $this->assertEmpty($layer[1]['_embedded']['nodes']);
     $layer = $layer[0]['_embedded']['nodes'];
     $this->assertEquals($page11->getUuid(), $layer[0]['id']);
     $this->assertEquals('test-1-1', $layer[0]['title']);
     $this->assertTrue($layer[0]['hasChildren']);
     $this->assertEmpty($layer[0]['_embedded']['nodes']);
 }