public function testNodeDelete() { $this->deleteEvent->getStructures()->willReturn([$this->structure]); $this->handler->invalidateStructure($this->structure->reveal())->shouldBeCalled(); $this->subscriber->onContentNodePreDelete($this->deleteEvent->reveal()); $this->subscriber->onContentNodePostDelete($this->deleteEvent->reveal()); }
/** * Returns a rendered structure. * * @param StructureInterface $structure The structure, which has been loaded for rendering * @param array $attributes Additional attributes, which will be passed to twig * @param bool $preview Defines if the site is rendered in preview mode * @param bool $partial Defines if only the content block of the template should be rendered * * @return Response */ protected function renderStructure(StructureInterface $structure, $attributes = [], $preview = false, $partial = false) { // extract format twig file if (!$preview) { $request = $this->getRequest(); $requestFormat = $request->getRequestFormat(); } else { $requestFormat = 'html'; } $viewTemplate = $structure->getView() . '.' . $requestFormat . '.twig'; try { // get attributes to render template $data = $this->getAttributes($attributes, $structure, $preview); // if partial render only content block else full page if ($partial) { $content = $this->renderBlock($viewTemplate, 'content', $data); } else { $content = parent::renderView($viewTemplate, $data); } return new Response($content); } catch (InvalidArgumentException $e) { // template not found throw new HttpException(406, 'Error encountered when rendering content', $e); } }
/** * extracts sequence information from property name. * * @param StructureInterface $content * @param string $property sequence like (block,1,title,0) * * @return array|bool */ public function getSequence(StructureInterface $content, $property) { if (false !== strpos($property, ',')) { $sequence = explode(',', $property); $propertyPath = []; $indexSequence = []; $propertyInstance = $content->getProperty($sequence[0]); for ($i = 1; $i < sizeof($sequence); ++$i) { // is not integer if (!ctype_digit(strval($sequence[$i]))) { $propertyPath[] = $sequence[$i]; if ($propertyInstance instanceof BlockPropertyInterface) { $lastIndex = $indexSequence[sizeof($indexSequence) - 1]; unset($indexSequence[sizeof($indexSequence) - 1]); $indexSequence = array_values($indexSequence); $propertyInstance = $propertyInstance->getProperties($lastIndex)->getProperty($sequence[$i]); } } else { $indexSequence[] = intval($sequence[$i]); } } return ['sequence' => $sequence, 'propertyPath' => $propertyPath, 'property' => $propertyInstance, 'index' => $indexSequence]; } return false; }
public function testDisableCache() { // disable cache $this->structure->getCacheLifeTime()->willReturn(0); $this->response->setPublic()->shouldNotBeCalled(); $this->response->setMaxAge($this->maxAge)->shouldNotBeCalled(); $this->response->setSharedMaxAge($this->sharedMaxAge)->shouldNotBeCalled(); $this->handler->updateResponse($this->response->reveal(), $this->structure->reveal()); }
public function updateResponse(Response $response, StructureInterface $structure) { $tags = [$this->getBanKey($structure->getUuid())]; foreach ($structure->getProperties(true) as $property) { foreach ($this->getReferencedUuids($property) as $uuid) { $tags[] = $this->getBanKey($uuid); } } $response->headers->set(self::TAGS_HEADER, implode(',', $tags)); }
protected function setUp() { parent::setUp(); $this->contactManager = $this->prophesize(ContactManagerInterface::class); $this->accountManager = $this->prophesize(ContactManagerInterface::class); $this->node = $this->prophesize(Node::class); $this->property = $this->prophesize(PropertyInterface::class); $this->structure = $this->prophesize(StructureInterface::class); $this->structure->getLanguageCode()->willReturn($this->locale); $this->structure->getWebspaceKey()->willReturn($this->webspaceKey); $this->property->getStructure()->willReturn($this->structure->reveal()); $this->serializer = $this->prophesize(Serializer::class); }
/** * {@inheritDoc} */ public function updateResponse(Response $response, StructureInterface $structure) { if (!$structure instanceof PageInterface) { return; } // mark the response as either public or private $response->setPublic(); // set the private and shared max age $response->setMaxAge($this->maxAge); $response->setSharedMaxAge($this->sharedMaxAge); $proxyTtl = $this->usePageTtl ? $response->getAge() + intval($structure->getCacheLifeTime()) : $response->getAge(); // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...) $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl); }
/** * 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; }
/** * @dataProvider provideLifecycle */ public function testLifecycle($options, $shouldInvalidate) { if ($options['has_structure']) { $this->request->attributes->set('structure', $this->structure->reveal()); } if ($options['preview']) { $this->request->query->set('preview', true); } $this->filterResponseEvent->getResponse()->willReturn($this->response); $this->filterResponseEvent->getRequest()->willReturn($this->request); $this->filterResponseEvent->isMasterRequest()->willReturn($options['is_master_request']); $invalidateProphecy = $this->handler->updateResponse($this->response, Argument::any()); if ($shouldInvalidate) { $invalidateProphecy->shouldBeCalled(); } else { $invalidateProphecy->shouldNotBeCalled(); } $this->subscriber->onResponse($this->filterResponseEvent->reveal()); }
/** * {@inheritdoc} */ public function updateResponse(Response $response, StructureInterface $structure) { if (!$structure instanceof PageInterface) { return; } $cacheLifetimeData = $structure->getCacheLifeTime(); $cacheLifetime = $this->cacheLifetimeResolver->resolve($cacheLifetimeData['type'], $cacheLifetimeData['value']); // when structure cache-lifetime disabled - return if (0 === $cacheLifetime) { return; } // mark the response as either public or private $response->setPublic(); // set the private and shared max age $response->setMaxAge($this->maxAge); $response->setSharedMaxAge($this->sharedMaxAge); $proxyTtl = $this->usePageTtl ? $response->getAge() + $cacheLifetime : $response->getAge(); // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...) $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl); }
public function testInvalidate() { $this->structure->hasTag('sulu.rlp')->willReturn(true); $this->structure->getPropertyValueByTagName('sulu.rlp')->willReturn('/path/to'); $this->structure->getLanguageCode()->willReturn($this->languageCode); $this->structure->getWebspaceKey()->willReturn($this->webspaceKey); $urls = ['/path/to/1', '/path/to/2']; $this->webspaceManager->findUrlsByResourceLocator('/path/to', $this->env, $this->languageCode, $this->webspaceKey)->willReturn($urls); $this->proxyClient->purge($urls[0])->shouldBeCalled(); $this->proxyClient->purge($urls[1])->shouldBeCalled(); $this->proxyClient->flush()->shouldBeCalled(); $this->webspaceManager->findUrlsByResourceLocator(Argument::any())->shouldNotBeCalled(); $this->handler->invalidateStructure($this->structure->reveal()); $this->handler->flush(); }
/** * checks if content should be displayed. * * @param StructureInterface $content * @param string|null $context * * @return bool */ public function inNavigation(StructureInterface $content, $context = null) { $contexts = $content->getNavContexts(); if ($content->getNodeState() !== Structure::STATE_PUBLISHED) { // if node state is not published do not show page return false; } if (is_array($contexts) && ($context === null || in_array($context, $contexts))) { // all contexts or content has context return true; } // do not show return false; }
public function testUpdateResponse() { $this->handler1->updateResponse($this->response->reveal(), $this->structure->reveal())->shouldBeCalled(); $this->handler2->updateResponse($this->response->reveal(), $this->structure->reveal())->shouldBeCalled(); $this->handler->updateResponse($this->response->reveal(), $this->structure->reveal()); }
/** * returns finished Node (with _links and _embedded). * * @param StructureInterface $structure * @param string $webspaceKey * @param string $languageCode * @param int $depth * @param bool $complete * @param bool $excludeGhosts * @param string|null $extension * * @return array */ protected function prepareNode(StructureInterface $structure, $webspaceKey, $languageCode, $depth = 1, $complete = true, $excludeGhosts = false, $extension = null) { $result = $structure->toArray($complete); // add default embedded property with empty nodes array $result['_embedded'] = []; $result['_embedded']['nodes'] = []; // add api links $result['_links'] = ['self' => ['href' => $this->apiBasePath . '/' . $structure->getUuid() . ($extension !== null ? '/' . $extension : '')], 'children' => ['href' => $this->apiBasePath . '?parent=' . $structure->getUuid() . '&depth=' . $depth . '&webspace=' . $webspaceKey . '&language=' . $languageCode . ($excludeGhosts === true ? '&exclude-ghosts=true' : '')]]; return $result; }
/** * {@inheritdoc} */ public function load(NodeInterface $node, $webspaceKey, $languageCode) { $data = []; foreach ($this->excerptStructure->getProperties() as $property) { $contentType = $this->contentTypeManager->get($property->getContentTypeName()); $contentType->read($node, new TranslatedProperty($property, $languageCode . '-' . $this->additionalPrefix, $this->languageNamespace), $webspaceKey, $languageCode, null); $data[$property->getName()] = $contentType->getContentData($property); } return $data; }
/** * returns finished Node (with _links and _embedded). * * @param StructureInterface $structure * @param string $webspaceKey * @param string $languageCode * @param int $depth * @param bool $complete * @param bool $excludeGhosts * @param string|null $extension * * @return array * * @deprecated This part should be split into a serialization handler and using the hateoas bundle */ protected function prepareNode(StructureInterface $structure, $webspaceKey, $languageCode, $depth = 1, $complete = true, $excludeGhosts = false, $extension = null) { $result = $structure->toArray($complete); // add default embedded property with empty nodes array $result['_embedded'] = []; $result['_embedded']['nodes'] = []; // add api links $result['_links'] = ['self' => ['href' => $this->apiBasePath . '/' . $structure->getUuid() . ($extension !== null ? '/' . $extension : '')], 'children' => ['href' => $this->apiBasePath . '?parent=' . $structure->getUuid() . '&depth=' . $depth . '&webspace=' . $webspaceKey . '&language=' . $languageCode . ($excludeGhosts === true ? '&exclude-ghosts=true' : '')]]; if ($this->tokenStorage && ($token = $this->tokenStorage->getToken())) { $result['_permissions'] = $this->accessControlManager->getUserPermissions(new SecurityCondition('sulu.webspaces.' . $webspaceKey, $languageCode, SecurityBehavior::class, $structure->getUuid()), $token->getUser()); } return $result; }
private function copyNode($srcLocale, $destLocale, StructureInterface $structure, $overwrite = false) { if (!$overwrite) { $destStructure = $this->contentMapper->load($structure->getUuid(), null, $destLocale, true); if (!($destStructure->getType() && $destStructure->getType()->getName() === 'ghost')) { $this->output->writeln('<info>Processing aborted: </info>' . $structure->getNodeName() . ' <comment>(use overwrite option to force)</comment>'); return; } } $this->contentMapper->copyLanguage($structure->getUuid(), $structure->getChanger(), null, $srcLocale, $destLocale, Structure::TYPE_SNIPPET); $this->output->writeln('<info>Processing: </info>' . $structure->getNodeName()); }
private function copyNode($webspaceKey, $srcLocale, $destLocale, StructureInterface $structure, $overwrite = false) { if (!$overwrite) { $destStructure = $this->contentMapper->load($structure->getUuid(), $webspaceKey, $destLocale, true); if (!($destStructure->getType() && $destStructure->getType()->getName() === 'ghost')) { $this->output->writeln('<info>Processing aborted: </info>' . $structure->getPath() . ' <comment>(use overwrite option to force)</comment>'); return; } } if ($structure->getType() && $structure->getType()->getName() === 'ghost') { $this->output->writeln('<info>Processing aborted: </info>' . $structure->getPath() . ' <comment>(source language does not exist)</comment>'); return; } try { $this->contentMapper->copyLanguage($structure->getUuid(), $structure->getChanger(), $webspaceKey, $srcLocale, $destLocale); $this->output->writeln('<info>Processing: </info>' . $structure->getPath()); } catch (ResourceLocatorAlreadyExistsException $e) { $this->output->writeln(sprintf('<info>Processing aborted: </info> %s <comment>Resource Locator "%s" already exists', $structure->getPath(), $structure->getResourceLocator())); } }
public function indexCallback(StructureInterface $structure, $preview = false, $partial = false) { return new Response($this->render($structure->getPropertyValue('title'), $structure->getPropertyValue('article'), $structure->getPropertyValue('block'), $partial)); }
/** * {@inheritdoc} */ public function copyFrom(StructureInterface $structure) { foreach ($this->getProperties(true) as $property) { if ($structure->hasProperty($property->getName())) { $property->setValue($structure->getPropertyValue($property->getName())); } } $this->setDocument($structure->getDocument()); }
/** * @param StructureInterface $structure * @param array $parts * @param string $separator default '-' * * @return string */ private function implodeRlpParts(StructureInterface $structure, array $parts, $separator = '-') { $title = ''; // concat rlp parts in sort of priority foreach ($structure->getPropertiesByTagName('sulu.rlp.part') as $property) { $title = $parts[$property->getName()] . $separator . $title; } $title = substr($title, 0, -1); return $title; }
/** * Returns select of a single structure with title and url selector. */ private function buildSelectForStructure($locale, StructureInterface $structure, &$names) { $nodeNameProperty = $structure->getProperty('title'); $result = ''; $name = $this->getTranslatedProperty($nodeNameProperty, $locale)->getName(); if (!in_array($name, $names)) { $names[] = $name; $result .= ', ' . $this->buildSelector($name); } if ($structure->hasTag('sulu.rlp')) { $urlProperty = $structure->getPropertyByTagName('sulu.rlp'); $name = $this->getTranslatedProperty($urlProperty, $locale)->getName(); if ($urlProperty->getContentTypeName() !== 'resource_locator' && !in_array($name, $names)) { $names[] = $name; $result .= ', ' . $this->buildSelector($name); } } return $result; }
/** * {@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; }
/** * @param Request $request * @param StructureInterface $content * * @return Route */ protected function getStructureRoute(Request $request, $content) { return new Route($request->getPathInfo(), ['_controller' => $content->getController(), 'structure' => $content]); }
/** * {@inheritdoc} */ public function copyFrom(StructureInterface $structure) { $this->setWebspaceKey($structure->getWebspaceKey()); $this->setLanguageCode($structure->getLanguageCode()); $this->setUuid($structure->getUuid()); $this->setChanged($structure->getChanged()); $this->setChanger($structure->getChanger()); $this->setCreated($structure->getCreated()); $this->setCreator($structure->getCreator()); $this->setPublished($structure->getPublished()); $this->setPath($structure->getPath()); $this->setNodeType($structure->getNodeType()); $this->setHasTranslation($structure->getHasTranslation()); }