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(); } }
/** * {@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(); } }
/** * {@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()); }
protected function setUp() { $this->purgeDatabase(); $this->initOrm(); $this->initPhpcr(); $this->sessionManager = $this->getContainer()->get('sulu.phpcr.session'); $this->session = $this->sessionManager->getSession(); $this->rlpMapper = new PhpcrMapper($this->getContainer()->get('sulu.phpcr.session')); $this->strategy = $this->getContainer()->get('sulu.content.rlp.strategy.tree'); $this->resourceLocator = new ResourceLocator($this->strategy, 'not-in-use'); }
/** * {@inheritdoc} */ public function restoreByPath($path, $webspaceKey, $languageCode, $segmentKey = null) { $rootNode = $this->getWebspaceRouteNode($webspaceKey, $languageCode, $segmentKey); $newRouteNode = $rootNode->getNode(ltrim($path, '/')); $currentRouteNode = $newRouteNode->getPropertyValue('sulu:content'); $contentNode = $currentRouteNode->getPropertyValue('sulu:content'); // change other history connections $this->iterateRouteNodes($currentRouteNode, function ($resourceLocator, NodeInterface $node) use(&$newRouteNode) { if ($node->getPropertyValue('sulu:history') === true) { $node->setProperty('sulu:content', $newRouteNode); } return false; }, $webspaceKey, $languageCode, $segmentKey); // change history $newRouteNode->setProperty('sulu:history', false); $currentRouteNode->setProperty('sulu:history', true); // set creation date $newRouteNode->setProperty('sulu:created', new DateTime()); $currentRouteNode->setProperty('sulu:created', new DateTime()); // set content $newRouteNode->setProperty('sulu:content', $contentNode); $currentRouteNode->setProperty('sulu:content', $newRouteNode); // save session $this->sessionManager->getSession()->save(); }
/** * 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(); }
/** * {@inheritdoc} */ public function getFilteredNodes(array $filterConfig, $languageCode, $webspaceKey, $preview = false, $api = false, $exclude = []) { $limit = isset($filterConfig['limitResult']) ? $filterConfig['limitResult'] : null; $initParams = ['config' => $filterConfig]; if ($exclude) { $initParams['excluded'] = $exclude; } $this->queryBuilder->init($initParams); $data = $this->queryExecutor->execute($webspaceKey, [$languageCode], $this->queryBuilder, true, -1, $limit); if ($api) { if (isset($filterConfig['dataSource'])) { if ($this->webspaceManager->findWebspaceByKey($filterConfig['dataSource']) !== null) { $node = $this->sessionManager->getContentNode($filterConfig['dataSource']); } else { $node = $this->sessionManager->getSession()->getNodeByIdentifier($filterConfig['dataSource']); } } else { $node = $this->sessionManager->getContentNode($webspaceKey); } $parentNode = $this->getParentNode($node->getIdentifier(), $webspaceKey, $languageCode); $result = $this->prepareNode($parentNode, $webspaceKey, $languageCode, 1, false); $result['_embedded']['nodes'] = $data; $result['total'] = count($result['_embedded']['nodes']); } else { $result = $data; } return $result; }
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']); }
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); }
public function __construct(SessionManagerInterface $sessionManager, PropertyEncoder $propertyEncoder, WebspaceManagerInterface $webspaceManager, LocalizationFinderInterface $localizationFinder, SuluNodeHelper $nodeHelper) { $this->sessionManager = $sessionManager; $this->propertyEncoder = $propertyEncoder; $this->webspaceManager = $webspaceManager; $this->localizationFinder = $localizationFinder; $this->nodeHelper = $nodeHelper; $this->session = $sessionManager->getSession(); $this->qomFactory = $this->session->getWorkspace()->getQueryManager()->getQOMFactory(); }
/** * 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); }
/** * {@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; }
/** * 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; }
/** * {@inheritdoc} */ public function getParentPath($uuid, $webspaceKey, $languageCode, $segmentKey = null) { $session = $this->sessionManager->getSession(); $contentNode = $session->getNodeByIdentifier($uuid); $parentNode = $contentNode->getParent(); try { return $this->loadByContent($parentNode, $webspaceKey, $languageCode, $segmentKey); } catch (ResourceLocatorNotFoundException $ex) { // parent node don´t have a resource locator return; } }
/** * 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() . '\')'; }
/** * 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())); }
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')); }