Returns the content path for given webspace.
public getContentPath ( string $webspaceKey ) : string | ||
$webspaceKey | string | |
return | string |
/** * {@inheritdoc} */ public function execute($webspaceKey, $locales, ContentQueryBuilderInterface $contentQueryBuilder, $flat = true, $depth = -1, $limit = null, $offset = null, $moveUp = false) { if ($this->stopwatch) { $this->stopwatch->start('ContentQuery::execute.build-query'); } list($sql2, $fields) = $contentQueryBuilder->build($webspaceKey, $locales); if ($this->stopwatch) { $this->stopwatch->stop('ContentQuery::execute.build-query'); $this->stopwatch->start('ContentQuery::execute.execute-query'); } $query = $this->createSql2Query($sql2, $limit, $offset); $queryResult = $query->execute(); if ($this->stopwatch) { $this->stopwatch->stop('ContentQuery::execute.execute-query'); $this->stopwatch->start('ContentQuery::execute.preload-nodes.get-paths'); } // this preloads all node which should are selected in the statement before // prevent the system to load each node individual $rootDepth = substr_count($this->sessionManager->getContentPath($webspaceKey), '/'); $paths = []; /** @var Row $row */ foreach ($queryResult as $row) { $pageDepth = substr_count($row->getPath('page'), '/') - $rootDepth; if ($depth === null || $depth < 0 || $depth > 0 && $pageDepth <= $depth) { $paths[] = $row->getPath('page'); } } if ($this->stopwatch) { $this->stopwatch->stop('ContentQuery::execute.preload-nodes.get-paths'); $this->stopwatch->start('ContentQuery::execute.preload-nodes.execute'); } $this->sessionManager->getSession()->getNodes($paths); if ($this->stopwatch) { $this->stopwatch->stop('ContentQuery::execute.preload-nodes.execute'); $this->stopwatch->start('ContentQuery::execute.rowsToList'); } $result = $this->contentMapper->convertQueryResultToArray($queryResult, $webspaceKey, $locales, $fields, $depth, $contentQueryBuilder->getPublished()); if ($this->stopwatch) { $this->stopwatch->stop('ContentQuery::execute.rowsToList'); } if (!$flat) { if ($this->stopwatch) { $this->stopwatch->start('ContentQuery::execute.build-tree'); } $converter = new ListToTreeConverter($moveUp); $result = $converter->convert($result); if ($this->stopwatch) { $this->stopwatch->stop('ContentQuery::execute.build-tree'); } } return $result; }
/** * {@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(); }
/** * 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); }
private function upgradeLocale(Webspace $webspace, Localization $localization, OutputInterface $output) { $output->writeln(' > Upgrade Locale: ' . $localization->getLocalization('-')); $contentNode = $this->liveSession->getNode($this->sessionManager->getContentPath($webspace->getKey())); $this->upgradeNode($contentNode, $webspace, $localization, $output); $this->upgradeByParent($contentNode, $webspace, $localization, $output); }
/** * @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; }
/** * {@inheritdoc} */ public function convertQueryResultToArray(QueryResultInterface $queryResult, $webspaceKey, $locales, $fields, $maxDepth) { $rootDepth = substr_count($this->sessionManager->getContentPath($webspaceKey), '/'); $result = array(); 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); if (false === $item || in_array($item, $result)) { continue; } $result[] = $item; } } } return $result; }
/** * 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()), '/'); }