상속: extends Symfony\Component\DependencyInjection\ContainerAwareInterface
예제 #1
0
 public function warmUp($cacheDir)
 {
     // warmup the pages
     $this->structureManager->getStructures(Structure::TYPE_PAGE);
     // warm up the snippets
     $this->structureManager->getStructures(Structure::TYPE_SNIPPET);
 }
예제 #2
0
 public function testResolve()
 {
     $this->contentTypeManager->get('content_type')->willReturn($this->contentType);
     $this->contentType->getViewData(Argument::any())->willReturn('view');
     $this->contentType->getContentData(Argument::any())->willReturn('content');
     $excerptExtension = $this->prophesize('Sulu\\Component\\Content\\Extension\\ExtensionInterface');
     $excerptExtension->getContentData(['test1' => 'test1'])->willReturn(['test1' => 'test1']);
     $this->structureManager->getExtension('test', 'excerpt')->willReturn($excerptExtension);
     $property = $this->prophesize('Sulu\\Component\\Content\\Compat\\PropertyInterface');
     $property->getName()->willReturn('property');
     $property->getContentTypeName()->willReturn('content_type');
     $structure = $this->prophesize('Sulu\\Component\\Content\\Compat\\Structure\\PageBridge');
     $structure->getKey()->willReturn('test');
     $structure->getExt()->willReturn(new ExtensionContainer(['excerpt' => ['test1' => 'test1']]));
     $structure->getUuid()->willReturn('some-uuid');
     $structure->getProperties(true)->willReturn([$property->reveal()]);
     $structure->getCreator()->willReturn(1);
     $structure->getChanger()->willReturn(1);
     $structure->getCreated()->willReturn('date');
     $structure->getChanged()->willReturn('date');
     $structure->getPublished()->willReturn('date');
     $structure->getPath()->willReturn('test-path');
     $structure->getUrls()->willReturn(['en' => '/description', 'de' => '/beschreibung', 'es' => null]);
     $structure->getShadowBaseLanguage()->willReturn('en');
     $expected = ['extension' => ['excerpt' => ['test1' => 'test1']], 'uuid' => 'some-uuid', 'view' => ['property' => 'view'], 'content' => ['property' => 'content'], 'creator' => 1, 'changer' => 1, 'created' => 'date', 'changed' => 'date', 'published' => 'date', 'template' => 'test', 'urls' => ['en' => '/description', 'de' => '/beschreibung', 'es' => null], 'path' => 'test-path', 'shadowBaseLocale' => 'en'];
     $this->assertEquals($expected, $this->structureResolver->resolve($structure->reveal()));
 }
예제 #3
0
 /**
  * Return a structure bridge corresponding to the given document.
  *
  * @param BasePageDocument $document
  *
  * @return PageBridge
  */
 protected function documentToStructure(BasePageDocument $document)
 {
     $structure = $this->inspector->getStructureMetadata($document);
     $documentAlias = $this->inspector->getMetadata($document)->getAlias();
     $structureBridge = $this->structureManager->wrapStructure($documentAlias, $structure);
     $structureBridge->setDocument($document);
     return $structureBridge;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function generate($parts, $parentUuid, $webspaceKey, $languageCode, $templateKey, $segmentKey = null)
 {
     /** @var StructureInterface $structure */
     $structure = $this->structureManager->getStructure($templateKey);
     $title = $this->implodeRlpParts($structure, $parts);
     $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey);
     $resourceLocator = $resourceLocatorStrategy->generate($title, $parentUuid, $webspaceKey, $languageCode, $segmentKey);
     return ['resourceLocator' => $resourceLocator, '_links' => ['self' => $this->getBasePath() . '/generates']];
 }
예제 #5
0
 /**
  * Returns and caches structures for given webspace.
  *
  * @param string $webspaceKey
  *
  * @return array
  */
 protected function loadStructures($webspaceKey)
 {
     $structures = [];
     $keys = [];
     foreach ($this->structureManager->getStructures() as $page) {
         /* @var PageBridge $page */
         $template = sprintf('%s.html.twig', $page->getView());
         if ($this->templateExists($template)) {
             $keys[] = $page->getKey();
             $structures[] = $page;
         }
     }
     $this->cache->save($webspaceKey, $keys);
     return $structures;
 }
예제 #6
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());
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function generate($parts, $parentUuid, $uuid, $webspaceKey, $languageCode, $templateKey, $segmentKey = null)
 {
     /** @var StructureInterface $structure */
     $structure = $this->structureManager->getStructure($templateKey);
     $title = $this->implodeRlpParts($structure, $parts);
     if ($parentUuid !== null) {
         $parentPath = $this->strategy->loadByContentUuid($parentUuid, $webspaceKey, $languageCode, $segmentKey);
         $result = $this->strategy->generate($title, $parentPath, $webspaceKey, $languageCode, $segmentKey);
     } elseif ($uuid !== null) {
         $result = $this->strategy->generateForUuid($title, $uuid, $webspaceKey, $languageCode, $segmentKey);
     } else {
         $parentPath = '/';
         $result = $this->strategy->generate($title, $parentPath, $webspaceKey, $languageCode, $segmentKey);
     }
     return ['resourceLocator' => $result, '_links' => ['self' => $this->getBasePath() . '/generates']];
 }
예제 #8
0
 /**
  * Returns a select statement for excerpt data.
  */
 private function buildSelectorForExcerpt($locale, &$additionalFields)
 {
     $excerptStructure = $this->structureManager->getStructure('excerpt');
     $extension = $this->structureManager->getExtension('', 'excerpt');
     foreach ($excerptStructure->getProperties(true) as $property) {
         $additionalFields[$locale][] = ['extension' => $extension, 'target' => 'excerpt', 'property' => $property->getName(), 'name' => $property->getName()];
     }
 }
예제 #9
0
 /**
  * Returns and caches excerpt-structure.
  *
  * @return StructureInterface
  */
 private function getExcerptStructure()
 {
     if ($this->excerptStructure === null) {
         $this->excerptStructure = $this->structureManager->getStructure(self::EXCERPT_EXTENSION_NAME);
         $this->excerptStructure->setLanguageCode($this->languageCode);
     }
     return $this->excerptStructure;
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function updateTemplate($template, $userId, $contentUuid, $webspaceKey, $locale)
 {
     /** @var PageBridge $structure */
     $structure = $this->fetchStructure($userId, $contentUuid, $webspaceKey, $locale);
     /** @var PageBridge $newStructure */
     $newStructure = $this->structureManager->getStructure($template);
     $newStructure->copyFrom($structure);
     $this->saveStructure($newStructure, $userId, $contentUuid, $webspaceKey, $locale);
 }
예제 #11
0
 private function loadStructures($webspaceKey)
 {
     $before = $this->activeTheme->getName();
     $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);
     $this->activeTheme->setName($webspace->getTheme()->getKey());
     $structures = [];
     $keys = [];
     foreach ($this->structureManager->getStructures() as $page) {
         /* @var PageBridge $page */
         $template = sprintf('%s.html.twig', $page->getView());
         if ($this->templateExists($template)) {
             $keys[] = $page->getKey();
             $structures[] = $page;
         }
     }
     $this->activeTheme->setName($before);
     $this->cache->save($webspaceKey, $keys);
     return $structures;
 }
예제 #12
0
 /**
  * {@inheritDoc}
  */
 public function resolve(StructureInterface $structure)
 {
     $data = ['view' => [], 'content' => [], 'uuid' => $structure->getUuid(), 'creator' => $structure->getCreator(), 'changer' => $structure->getChanger(), 'created' => $structure->getCreated(), 'changed' => $structure->getChanged(), 'template' => $structure->getKey(), 'path' => $structure->getPath()];
     if ($structure instanceof PageBridge) {
         $data['extension'] = $structure->getExt()->toArray();
         $data['urls'] = $structure->getUrls();
         $data['published'] = $structure->getPublished();
         $data['shadowBaseLocale'] = $structure->getShadowBaseLanguage();
         foreach ($data['extension'] as $name => $value) {
             $extension = $this->structureManager->getExtension($structure->getKey(), $name);
             $data['extension'][$name] = $extension->getContentData($value);
         }
     }
     foreach ($structure->getProperties(true) as $property) {
         $contentType = $this->contentTypeManager->get($property->getContentTypeName());
         $data['view'][$property->getName()] = $contentType->getViewData($property);
         $data['content'][$property->getName()] = $contentType->getContentData($property);
     }
     return $data;
 }
예제 #13
0
 /**
  * Return a structure bridge corresponding to the given document.
  *
  * @param StructureBehavior $document
  *
  * @return StructureBridge
  *
  * @deprecated
  */
 private function documentToStructure(StructureBehavior $document)
 {
     if (null === $document) {
         return;
     }
     $structure = $this->documentInspector->getStructureMetadata($document);
     $documentAlias = $this->documentInspector->getMetadata($document)->getAlias();
     $structureBridge = $this->structureManager->wrapStructure($documentAlias, $structure);
     $structureBridge->setDocument($document);
     return $structureBridge;
 }
예제 #14
0
 /**
  * Resolve url property.
  *
  * @param Row $row
  * @param string $locale
  *
  * @return string
  */
 private function resolveUrl(Row $row, $locale)
 {
     if ($this->resolveProperty($row, $locale . 'State', $locale) !== WorkflowStage::PUBLISHED) {
         return;
     }
     $template = $this->resolveProperty($row, 'template', $locale);
     if (empty($template)) {
         return;
     }
     $structure = $this->structureManager->getStructure($template);
     if (!$structure->hasTag('sulu.rlp')) {
         return;
     }
     $propertyName = $structure->getPropertyByTagName('sulu.rlp')->getName();
     return $this->resolveProperty($row, $propertyName, $locale);
 }
예제 #15
0
파일: Webspace.php 프로젝트: sulu/sulu
 /**
  * Loops all documents and imports all properties of the documents.
  *
  * @param BasePageDocument $document
  * @param string $structureType
  * @param string $webspaceKey
  * @param string $locale
  * @param string $format
  * @param array $data
  */
 protected function setDocumentData(BasePageDocument $document, $structureType, $webspaceKey, $locale, $format, $data)
 {
     $structure = $this->structureManager->getStructure($structureType);
     $properties = $structure->getProperties(true);
     $node = $this->documentRegistry->getNodeForDocument($document);
     $node->setProperty(sprintf('i18n:%s-template', $locale), $structureType);
     $state = $this->getParser($format)->getPropertyData('state', $data, null, null, 2);
     $node->setProperty(sprintf('i18n:%s-state', $locale), $state);
     if ($this->getParser($format)->getPropertyData('title', $data) === '') {
         $this->addException(sprintf('Document(%s) has not set any title', $document->getUuid()), 'ignore');
         return false;
     }
     // import all content data
     foreach ($properties as $property) {
         $value = $this->getParser($format)->getPropertyData($property->getName(), $data, $property->getContentTypeName());
         // don't generate a new url when one exists
         $doImport = true;
         if ($property->getContentTypeName() == 'resource_locator') {
             $doImport = false;
             if (!$document->getResourceSegment()) {
                 $doImport = true;
                 $parent = $document->getParent();
                 if ($parent instanceof BasePageDocument) {
                     $parentUuid = $parent->getUuid();
                     $value = $this->generateUrl($structure->getPropertiesByTagName('sulu.rlp.part'), $parentUuid, $webspaceKey, $locale, $format, $data);
                 }
             }
         }
         // import property data
         if ($doImport) {
             $this->importProperty($property, $node, $structure, $value, $webspaceKey, $locale, $format);
         }
     }
     // import extensions
     $extensions = $this->extensionManager->getExtensions($structureType);
     foreach ($extensions as $key => $extension) {
         $this->importExtension($extension, $key, $node, $data, $webspaceKey, $locale, $format);
     }
     // set required data
     $document->setTitle($this->getParser($format)->getPropertyData('title', $data));
     return true;
 }
예제 #16
0
 /**
  * adopts resource locator of children by iteration.
  *
  * @param NodeInterface $contentNode
  * @param int           $userId
  * @param string        $webspaceKey
  * @param string        $languageCode
  * @param bool          $iterate
  * @param string        $segmentKey
  */
 private function adaptResourceLocators(NodeInterface $contentNode, $userId, $webspaceKey, $languageCode, $segmentKey = null, $iterate = true)
 {
     foreach ($contentNode->getNodes() as $node) {
         // determine structure
         $templatePropertyName = $this->nodeHelper->getTranslatedPropertyName('template', $languageCode);
         if (!$node->hasProperty($templatePropertyName)) {
             continue;
         }
         $template = $node->getPropertyValue($templatePropertyName);
         $structure = $this->structureManager->getStructure($template);
         // only if rlp exists
         if ($structure->hasTag('sulu.rlp')) {
             // get rlp
             try {
                 $rlp = $this->loadByContent($node, $webspaceKey, $languageCode);
             } catch (ResourceLocatorNotFoundException $ex) {
                 $contentNode->getSession()->save();
                 $rlpPart = $node->getPropertyValue($this->nodeHelper->getTranslatedPropertyName('title', $languageCode));
                 $prentRlp = $this->mapper->getParentPath($node->getIdentifier(), $webspaceKey, $languageCode, $segmentKey);
                 // generate new resourcelocator
                 $rlp = $this->generate($rlpPart, $prentRlp, $webspaceKey, $languageCode);
             }
             // determine rlp property
             $property = $structure->getPropertyByTagName('sulu.rlp');
             $contentType = $this->contentTypeManager->get($property->getContentTypeName());
             $property->setValue($rlp);
             // write value to node
             $translatedProperty = $this->nodeHelper->getTranslatedProperty($property, $languageCode);
             $contentType->write($node, $translatedProperty, $userId, $webspaceKey, $languageCode, $segmentKey);
         }
         // for node move the tree will be copied to then there is the iteration over this function
         // for node copy the iteration is done by the content-type which calls over the move function
         //     recursively this function
         if ($iterate) {
             $this->adaptResourceLocators($node, $userId, $webspaceKey, $languageCode, $segmentKey);
         }
     }
 }
예제 #17
0
 /**
  * Finds the correct route for the current request.
  * It loads the correct data with the content mapper.
  *
  * @param Request $request A request against which to match
  *
  * @return \Symfony\Component\Routing\RouteCollection with all Routes that
  *                                                    could potentially match $request. Empty collection if nothing can
  *                                                    match
  */
 public function getRouteCollectionForRequest(Request $request)
 {
     $collection = new RouteCollection();
     // no portal information without localization supported
     if ($this->requestAnalyzer->getCurrentLocalization() === null && $this->requestAnalyzer->getMatchType() !== RequestAnalyzerInterface::MATCH_TYPE_PARTIAL && $this->requestAnalyzer->getMatchType() !== RequestAnalyzerInterface::MATCH_TYPE_REDIRECT) {
         return $collection;
     }
     $htmlExtension = '.html';
     $resourceLocator = $this->requestAnalyzer->getResourceLocator();
     if ($this->requestAnalyzer->getMatchType() == RequestAnalyzerInterface::MATCH_TYPE_REDIRECT || $this->requestAnalyzer->getMatchType() == RequestAnalyzerInterface::MATCH_TYPE_PARTIAL) {
         // redirect webspace correctly with locale
         $collection->add('redirect_' . uniqid(), $this->getRedirectWebSpaceRoute());
     } elseif ($request->getRequestFormat() === 'html' && substr($request->getPathInfo(), -strlen($htmlExtension)) === $htmlExtension) {
         // redirect *.html to * (without url)
         $collection->add('redirect_' . uniqid(), $this->getRedirectRoute($request, $this->getUrlWithoutEndingTrailingSlash($resourceLocator)));
     } else {
         // just show the page
         $portal = $this->requestAnalyzer->getPortal();
         $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization();
         $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($portal->getWebspace()->getKey());
         try {
             // load content by url ignore ending trailing slash
             /** @var PageDocument $document */
             $document = $this->documentManager->find($resourceLocatorStrategy->loadByResourceLocator(rtrim($resourceLocator, '/'), $portal->getWebspace()->getKey(), $locale), $locale, ['load_ghost_content' => false]);
             if (!$document->getTitle()) {
                 // If the title is empty the document does not exist in this locale
                 // Necessary because of https://github.com/sulu/sulu/issues/2724, otherwise locale could be checked
                 return $collection;
             }
             if (preg_match('/\\/$/', $resourceLocator) && $this->requestAnalyzer->getResourceLocatorPrefix()) {
                 // redirect page to page without slash at the end
                 $collection->add('redirect_' . uniqid(), $this->getRedirectRoute($request, $this->requestAnalyzer->getResourceLocatorPrefix() . rtrim($resourceLocator, '/')));
             } elseif ($document->getRedirectType() === RedirectType::INTERNAL) {
                 // redirect internal link
                 $redirectUrl = $this->requestAnalyzer->getResourceLocatorPrefix() . $document->getRedirectTarget()->getResourceSegment();
                 if ($request->getQueryString()) {
                     $redirectUrl .= '?' . $request->getQueryString();
                 }
                 $collection->add($document->getStructureType() . '_' . $document->getUuid(), $this->getRedirectRoute($request, $redirectUrl));
             } elseif ($document->getRedirectType() === RedirectType::EXTERNAL) {
                 $collection->add($document->getStructureType() . '_' . $document->getUuid(), $this->getRedirectRoute($request, $document->getRedirectExternal()));
             } elseif (!$this->checkResourceLocator()) {
                 return $collection;
             } else {
                 // convert the page to a StructureBridge because of BC
                 /** @var PageBridge $structure */
                 $structure = $this->structureManager->wrapStructure($this->documentInspector->getMetadata($document)->getAlias(), $this->documentInspector->getStructureMetadata($document));
                 $structure->setDocument($document);
                 // show the page
                 $collection->add($document->getStructureType() . '_' . $document->getUuid(), $this->getStructureRoute($request, $structure));
             }
         } catch (ResourceLocatorNotFoundException $exc) {
             // just do not add any routes to the collection
         } catch (ResourceLocatorMovedException $exc) {
             // old url resource was moved
             $collection->add($exc->getNewResourceLocatorUuid() . '_' . uniqid(), $this->getRedirectRoute($request, $this->requestAnalyzer->getResourceLocatorPrefix() . $exc->getNewResourceLocator()));
         } catch (RepositoryException $exc) {
             // just do not add any routes to the collection
         }
     }
     return $collection;
 }
예제 #18
0
 /**
  * initiates structure and properties.
  */
 private function initExcerptStructure()
 {
     $excerptStructure = $this->structureManager->getStructure(self::EXCERPT_EXTENSION_NAME);
     /** @var PropertyInterface $property */
     foreach ($excerptStructure->getProperties() as $property) {
         $this->properties[] = $property->getName();
     }
     return $excerptStructure;
 }
예제 #19
0
 /**
  * Invalidates the structure of the given document.
  *
  * @param $document
  */
 private function invalidateDocumentStructure($document)
 {
     $structureBridge = $this->structureManager->wrapStructure($this->documentInspector->getMetadata($document)->getAlias(), $this->documentInspector->getStructureMetadata($document));
     $structureBridge->setDocument($document);
     $this->structureHandler->invalidateStructure($structureBridge);
 }