Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $webspaceKey = $input->getArgument('webspaceKey');
     $locale = $input->getArgument('locale');
     $basePath = $input->getOption('base-path');
     $dryRun = $input->getOption('dry-run');
     $this->session = $this->getContainer()->get('doctrine_phpcr')->getManager()->getPhpcrSession();
     $this->sessionManager = $this->getContainer()->get('sulu.phpcr.session');
     $this->output = $output;
     $path = $this->sessionManager->getRoutePath($webspaceKey, $locale);
     $relativePath = $basePath !== null ? '/' . ltrim($basePath, '/') : '/';
     $fullPath = rtrim($path . $relativePath, '/');
     if (!$this->session->nodeExists($fullPath)) {
         $this->output->write('<error>Resource-Locator "' . $relativePath . '" not found</error>');
         return;
     }
     $node = $this->session->getNode($fullPath);
     $this->cleanup($node, $path, $dryRun);
     if (false === $dryRun) {
         $this->output->writeln('<info>Saving ...</info>');
         $this->session->save();
         $this->output->writeln('<info>Done</info>');
     } else {
         $this->output->writeln('<info>Dry run complete</info>');
     }
 }
Beispiel #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));
 }
Beispiel #3
0
 public function initialize(OutputInterface $output, $purge = false)
 {
     $nodeTypeManager = $this->sessionManager->getSession()->getWorkspace()->getNodeTypeManager();
     foreach ([new CustomUrlNodeType(), new CustomUrlRouteNodeType()] as $nodeType) {
         $nodeTypeManager->registerNodeType($nodeType, true);
     }
     /** @var Webspace $webspace */
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         $itemsPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%custom_urls%', '%custom_urls_items%']);
         $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%custom_urls%', '%custom_urls_routes%']);
         $output->writeln(sprintf('  <info>%s</info>:', $webspace->getName()));
         if (true === $this->nodeManager->has($itemsPath)) {
             $output->writeln(sprintf('  [ ] <info>items path:</info>: %s ', $itemsPath));
         } else {
             $output->writeln(sprintf('  [+] <info>items path:</info>: %s ', $itemsPath));
             $this->nodeManager->createPath($itemsPath);
         }
         if (true === $this->nodeManager->has($routesPath)) {
             $output->writeln(sprintf('  [ ] <info>items path:</info>: %s ', $routesPath));
         } else {
             $output->writeln(sprintf('  [+] <info>items path:</info>: %s ', $routesPath));
             $this->nodeManager->createPath($routesPath);
         }
         $this->nodeManager->save();
     }
 }
Beispiel #4
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));
 }
Beispiel #5
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();
     }
 }
Beispiel #6
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());
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         $contentPath = $this->sessionManager->getContentPath($webspace->getKey());
         $this->context->getOutput()->writeln('Default workspace');
         $this->traverse($this->defaultSession->getNode($contentPath));
         $this->context->getOutput()->writeln('');
         $this->context->getOutput()->writeln('Live workspace');
         $this->traverse($this->liveSession->getNode($contentPath));
     }
     $this->defaultSession->save();
     $this->liveSession->save();
 }
Beispiel #8
0
 /**
  * Set the document parent to be the webspace content path
  * when the document has no parent.
  *
  * @param FormEvent $event
  */
 public function postSubmitDocumentParent(FormEvent $event)
 {
     $document = $event->getData();
     if ($document->getParent()) {
         return;
     }
     $form = $event->getForm();
     $webspaceKey = $form->getConfig()->getAttribute('webspace_key');
     $parent = $this->documentManager->find($this->sessionManager->getContentPath($webspaceKey));
     if (null === $parent) {
         throw new \InvalidArgumentException(sprintf('Could not determine parent for document with title "%s" in webspace "%s"', $document->getTitle(), $webspaceKey));
     }
     $document->setParent($parent);
 }
 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']);
 }
Beispiel #10
0
 /**
  * Create webspace root.
  *
  * @param string $key
  */
 private function createWebspaceRoot($key)
 {
     $session = $this->sessionManager->getSession();
     $cmf = $session->getNode('/cmf');
     // we should use the doctrinephpcrbundle repository initializer to do this.
     $webspace = $cmf->addNode($key);
     $webspace->addMixin('mix:referenceable');
     $content = $webspace->addNode('contents');
     $content->setProperty('i18n:en-template', 'default');
     $content->setProperty('i18n:en-creator', 1);
     $content->setProperty('i18n:en-created', new \DateTime());
     $content->setProperty('i18n:en-changer', 1);
     $content->setProperty('i18n:en-changed', new \DateTime());
     $content->setProperty('i18n:en-title', 'Homepage');
     $content->setProperty('i18n:en-state', WorkflowStage::PUBLISHED);
     $content->setProperty('i18n:en-published', new \DateTime());
     $content->setProperty('i18n:en-url', '/');
     $content->addMixin('sulu:home');
     $webspace->addNode('temp');
     $session->save();
     $nodes = $webspace->addNode('routes');
     foreach (['de', 'de_at', 'en', 'en_us', 'fr'] as $locale) {
         $localeNode = $nodes->addNode($locale);
         $localeNode->setProperty('sulu:content', $content);
         $localeNode->setProperty('sulu:history', false);
         $localeNode->addMixin('sulu:path');
     }
     $session->save();
 }
Beispiel #11
0
 /**
  * Updates the route for the given document and creates history routes if necessary.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof RouteBehavior) {
         return;
     }
     $node = $event->getNode();
     $node->setProperty(self::NODE_HISTORY_FIELD, $document->isHistory());
     $targetDocument = $document->getTargetDocument();
     if ($targetDocument instanceof HomeDocument || !$targetDocument instanceof WebspaceBehavior || !$targetDocument instanceof ResourceSegmentBehavior) {
         return;
     }
     // copy new route to old position
     $webspaceKey = $targetDocument->getWebspaceName();
     $locale = $this->documentInspector->getLocale($document);
     $routePath = $this->sessionManager->getRoutePath($webspaceKey, $locale, null) . $targetDocument->getResourceSegment();
     // create a route node if it is not a new document and the path changed
     $documentPath = $this->documentInspector->getPath($document);
     if ($documentPath && $documentPath != $routePath) {
         /** @var RouteDocument $newRouteDocument */
         $newRouteDocument = $this->documentManager->create('route');
         $newRouteDocument->setTargetDocument($targetDocument);
         $this->documentManager->persist($newRouteDocument, $locale, ['path' => $routePath, 'auto_create' => true]);
         $this->documentManager->publish($newRouteDocument, $locale);
         // change routes in old position to history
         $this->changeOldPathToHistoryRoutes($document, $newRouteDocument);
     }
 }
 private function exists($webspace, $locale, $route)
 {
     if ($route === '/') {
         return true;
     }
     $session = $this->sessionManager->getSession();
     $fullPath = sprintf('%s/%s', $this->sessionManager->getRoutePath($webspace, $locale), ltrim($route, '/'));
     return $session->nodeExists($fullPath);
 }
Beispiel #13
0
 /**
  * {@inheritdoc}
  */
 public function loadStringByWildcard($webspaceKey, $wildcard)
 {
     $webspaceNode = $this->deprecatedSessionManager->getWebspaceNode($webspaceKey);
     $properties = $webspaceNode->getProperties($this->getPropertyName($wildcard));
     $data = [];
     foreach ($properties as $property) {
         $data[substr($property->getName(), 9)] = $property->getString();
     }
     return $data;
 }
Beispiel #14
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $webspaceKey = $input->getArgument('webspaceKey');
     $locale = $input->getArgument('locale');
     $basePath = $input->getOption('base-path');
     $dryRun = $input->getOption('dry-run');
     $path = $this->sessionManager->getRoutePath($webspaceKey, $locale);
     $relativePath = $basePath !== null ? '/' . ltrim($basePath, '/') : '/';
     $fullPath = rtrim($path . $relativePath, '/');
     $this->cleanSession($output, $this->defaultSession, $fullPath, $dryRun);
     $this->cleanSession($output, $this->liveSession, $fullPath, $dryRun);
     if (false === $dryRun) {
         $this->defaultSession->save();
         $this->liveSession->save();
         $output->writeln('<info>Save complete</info>');
     } else {
         $output->writeln('<info>Dry run complete</info>');
     }
 }
Beispiel #15
0
 /**
  * TODO: Move this to ResourceLocator repository>.
  *
  * {@inheritdoc}
  */
 public function restoreHistoryPath($path, $userId, $webspaceKey, $locale, $segmentKey = null)
 {
     $this->strategy->restoreByPath($path, $webspaceKey, $locale, $segmentKey);
     $content = $this->loadByResourceLocator($path, $webspaceKey, $locale, $segmentKey);
     $property = $content->getPropertyByTagName('sulu.rlp');
     $property->setValue($path);
     $node = $this->sessionManager->getSession()->getNodeByIdentifier($content->getUuid());
     $contentType = $this->contentTypeManager->get($property->getContentTypeName());
     $contentType->write($node, new TranslatedProperty($property, $locale, $this->namespaceRegistry->getPrefix('content_localized')), $userId, $webspaceKey, $locale, $segmentKey);
 }
Beispiel #16
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;
 }
Beispiel #17
0
 /**
  * returns a sql2 query.
  */
 private function createSql2Query($sql2, $limit = null, $offset = null)
 {
     $queryManager = $this->sessionManager->getSession()->getWorkspace()->getQueryManager();
     $query = $queryManager->createQuery($sql2, 'JCR-SQL2');
     if ($limit) {
         $query->setLimit($limit);
     }
     if ($offset) {
         $query->setOffset($offset);
     }
     return $query;
 }
Beispiel #18
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() . '\')';
 }
Beispiel #19
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;
 }
Beispiel #20
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'));
 }
Beispiel #21
0
 /**
  * Returns list of custom-url data-arrays.
  *
  * @param string $path
  *
  * @return \Iterator
  */
 public function findUrls($path)
 {
     $session = $this->sessionManager->getSession();
     $queryManager = $session->getWorkspace()->getQueryManager();
     $qomFactory = $queryManager->getQOMFactory();
     $queryBuilder = new QueryBuilder($qomFactory);
     $queryBuilder->addSelect('a', 'domainParts', 'domainParts')->addSelect('a', 'baseDomain', 'baseDomain');
     $queryBuilder->from($queryBuilder->qomf()->selector('a', 'nt:unstructured'));
     $queryBuilder->where($queryBuilder->qomf()->comparison($queryBuilder->qomf()->propertyValue('a', 'jcr:mixinTypes'), QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO, $queryBuilder->qomf()->literal('sulu:custom_url')));
     $queryBuilder->andWhere($queryBuilder->qomf()->descendantNode('a', $path));
     $query = $queryBuilder->getQuery();
     $result = $query->execute();
     return array_map(function (Row $item) {
         return $this->generator->generate($item->getValue('a.baseDomain'), json_decode($item->getValue('a.domainParts'), true));
     }, iterator_to_array($result->getRows()));
 }
 /**
  * @param string $title
  * @param string $locale
  * @param string $link
  *
  * @return PageDocument
  */
 private function createExternalLinkPage($title, $locale, $link)
 {
     $data['title'] = $title;
     $data['url'] = '/' . $title;
     /** @var PageDocument $document */
     $document = $this->documentManager->create('page');
     $document->setStructureType('simple');
     $document->setTitle($title);
     $document->setResourceSegment($data['url']);
     $document->setLocale($locale);
     $document->setRedirectType(RedirectType::EXTERNAL);
     $document->setRedirectExternal($link);
     $document->getStructure()->bind($data);
     $this->documentManager->persist($document, $locale, ['path' => $this->sessionManager->getContentPath('sulu_io') . '/' . $title, 'auto_create' => true]);
     $this->documentManager->flush();
     return $document;
 }
Beispiel #23
0
 /**
  * {@inheritdoc}
  */
 public function convertQueryResultToArray(QueryResultInterface $queryResult, $webspaceKey, $locales, $fields, $maxDepth, $onlyPublished = true)
 {
     $rootDepth = substr_count($this->sessionManager->getContentPath($webspaceKey), '/');
     $result = [];
     foreach ($locales as $locale) {
         foreach ($queryResult->getRows() as $row) {
             $pageDepth = substr_count($row->getPath('page'), '/') - $rootDepth;
             if ($maxDepth === null || $maxDepth < 0 || $maxDepth > 0 && $pageDepth <= $maxDepth) {
                 $item = $this->rowToArray($row, $locale, $webspaceKey, $fields, $onlyPublished);
                 if (false === $item || in_array($item, $result)) {
                     continue;
                 }
                 $result[] = $item;
             }
         }
     }
     return $result;
 }
 public function testSaveAnotherExists()
 {
     $data = $this->prepareData();
     $this->cache->warmUp(1, $data[0]->getUuid(), 'sulu_io', 'en');
     $this->cache->saveStructure($data[1], 1, $data[1]->getUuid(), 'sulu_io', 'en');
     $this->cache->saveStructure($data[0], 1, $data[0]->getUuid(), 'sulu_io', 'en');
     $result = $this->cache->fetchStructure(1, $data[0]->getUuid(), 'sulu_io', 'en');
     $this->assertNotEquals(false, $result);
     $result = json_decode($this->dataCache->fetch($this->getId(1, $data[0]->getUuid(), 'en')), true);
     $this->assertEquals('Testtitle', $result['document']['structure']['title']);
     $this->assertEquals('overview', $result['document']['structureType']);
     $session = $this->sessionManager->getSession();
     $node = $session->getNode('/cmf/sulu_io/contents/testtitle');
     $this->assertEquals('Testtitle', $node->getPropertyValue('i18n:en-title'));
     $this->assertEquals('overview', $node->getPropertyValue('i18n:en-template'));
     $session = $this->sessionManager->getSession();
     $node = $session->getNode('/cmf/sulu_io/contents/testtitle2');
     $this->assertEquals('Testtitle2', $node->getPropertyValue('i18n:en-title'));
     $this->assertEquals('overview', $node->getPropertyValue('i18n:en-template'));
 }
 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;
     }
 }
Beispiel #26
0
 /**
  * returns base path of routes from phpcr.
  *
  * @param string $webspaceKey  current session
  * @param string $languageCode
  * @param string $segmentKey
  *
  * @return string
  */
 private function getWebspaceRouteNodeBasePath($webspaceKey, $languageCode, $segmentKey)
 {
     return $this->sessionManager->getRoutePath($webspaceKey, $languageCode, $segmentKey);
 }
Beispiel #27
0
 /**
  * Resolves path for given row.
  *
  * @param Row $row
  * @param string $webspaceKey
  *
  * @return string
  */
 private function resolvePath(Row $row, $webspaceKey)
 {
     return '/' . ltrim(str_replace($this->sessionManager->getContentPath($webspaceKey), '', $row->getPath()), '/');
 }
 public function testLoadParentStartPage()
 {
     $this->setExpectedException('Sulu\\Bundle\\WebsiteBundle\\Twig\\Exception\\ParentNotFoundException', 'Parent for "321-321-321" not found (perhaps it is the startpage?)');
     $extension = new ContentTwigExtension($this->contentMapper->reveal(), $this->structureResolver, $this->sessionManager->reveal(), $this->requestAnalyzer->reveal());
     $extension->loadParent('321-321-321');
 }