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(); } }
public function findAvailableLocale($webspaceName, array $availableLocales, $locale) { if (!$webspaceName) { return; } // get localization object for querying parent localizations $webspace = $this->webspaceManager->findWebspaceByKey($webspaceName); $localization = $webspace->getLocalization($locale); if (null === $localization) { return; } $resultLocalization = null; // find first available localization in parents $resultLocalization = $this->findAvailableParentLocalization($availableLocales, $localization); // find first available localization in children, if no result is found yet if (!$resultLocalization) { $resultLocalization = $this->findAvailableChildLocalization($availableLocales, $localization); } // find any localization available, if no result is found yet if (!$resultLocalization) { $resultLocalization = $this->findAvailableLocalization($availableLocales, $webspace->getLocalizations()); } if (!$resultLocalization) { return; } return $resultLocalization->getLocale(); }
/** * {@inheritdoc} */ public function resolveForPreview($webspaceKey, $locale) { // take first portal url $portalInformation = $this->webspaceManager->getPortalInformations($this->environment); $portalUrl = array_keys($portalInformation)[0]; return ['request' => ['webspaceKey' => $webspaceKey, 'locale' => $locale, 'defaultLocale' => $locale, 'portalUrl' => $portalUrl, 'resourceLocatorPrefix' => '', 'resourceLocator' => '', 'get' => $this->requestStack->getCurrentRequest()->query->all(), 'post' => $this->requestStack->getCurrentRequest()->request->all(), 'analyticsKey' => $this->previewDefaults['analyticsKey']]]; }
public function testLoad() { $importedRouteCollection = new RouteCollection(); $importedRouteCollection->add('route1', new Route('/example/route1')); $importedRouteCollection->add('route2', new Route('/route2')); $portal1 = new Portal(); $portal1->setKey('sulu_lo'); $portal2 = new Portal(); $portal2->setKey('sulu_com'); $portalInformations = [new PortalInformation(null, null, $portal1, null, 'sulu.io/de'), new PortalInformation(null, null, $portal2, null, 'sulu.com')]; $this->loaderResolver->resolve(Argument::any(), Argument::any())->willReturn($this->loader->reveal()); $this->loader->load(Argument::any(), Argument::any())->willReturn($importedRouteCollection); $this->webspaceManager->getPortalInformations(Argument::any())->willReturn($portalInformations); $routeCollection = $this->portalLoader->load('', 'portal'); $this->assertCount(4, $routeCollection); $routes = $routeCollection->getIterator(); $this->assertArrayHasKey('sulu.io/de.route1', $routes); $this->assertArrayHasKey('sulu.io/de.route2', $routes); $this->assertArrayHasKey('sulu.com.route1', $routes); $this->assertArrayHasKey('sulu.com.route2', $routes); $this->assertEquals('/de/example/route1', $routeCollection->get('sulu.io/de.route1')->getPath()); $this->assertEquals('/de/route2', $routeCollection->get('sulu.io/de.route2')->getPath()); $this->assertEquals('/example/route1', $routeCollection->get('sulu.com.route1')->getPath()); $this->assertEquals('/route2', $routeCollection->get('sulu.com.route2')->getPath()); }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var Webspace $webspace */ foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { $this->upgradeWebspace($webspace, $output); } $this->liveSession->save(); }
/** * {@inheritdoc} */ public function getParameters() { $result = []; foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { $result[$webspace->getKey()] = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspace->getKey())->getInputType(); } return $result; }
/** * {@inheritdoc} */ public function initialize(OutputInterface $output, $purge = false) { $webspaces = $this->webspaceManager->getWebspaceCollection(); foreach ($webspaces as $webspace) { $this->initializeWebspace($output, $webspace); } $this->documentManager->flush(); }
/** * {@inheritdoc} */ protected function doEnhance(CustomUrlBehavior $customUrl, Webspace $webspace, array $defaults, Request $request) { $seo = ['noFollow' => $customUrl->isNoFollow(), 'noIndex' => $customUrl->isNoIndex()]; if ($customUrl->isCanonical()) { $resourceSegment = $customUrl->getTargetDocument()->getResourceSegment(); $seo['canonicalUrl'] = $this->webspaceManager->findUrlByResourceLocator($resourceSegment, $defaults['_environment'], $customUrl->getTargetLocale(), $webspace->getKey()); } return ['_seo' => $seo]; }
/** * @param $importedRoute * @param $importedRouteName */ private function generatePortalRoutes(Route $importedRoute, $importedRouteName) { foreach ($this->webspaceManager->getPortalInformations($this->environment) as $portalInformation) { $route = clone $importedRoute; $route->setHost($portalInformation->getHost()); $route->setPath($portalInformation->getPrefix() . $route->getPath()); $this->collection->add($portalInformation->getUrl() . '.' . $importedRouteName, $route); } }
/** * {@inheritDoc} */ public function getSecurityContexts() { $webspaceContexts = []; foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { /* @var Webspace $webspace */ $webspaceContexts[] = $this->securityContextPrefix . $webspace->getKey(); } return ['Sulu' => ['Webspaces' => $webspaceContexts]]; }
/** * {@inheritdoc} */ public function getSecurityContexts() { $webspaceContexts = []; foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { /* @var Webspace $webspace */ $webspaceContexts[] = self::SECURITY_CONTEXT_PREFIX . $webspace->getKey(); } return ['Sulu' => ['Webspaces' => $webspaceContexts]]; }
/** * {@inheritdoc} */ protected function doEnhance(CustomUrlBehavior $customUrl, Webspace $webspace, array $defaults, Request $request) { $resourceSegment = '/'; if ($customUrl->getTargetDocument() !== null) { $resourceSegment = $customUrl->getTargetDocument()->getResourceSegment(); } $url = $this->webspaceManager->findUrlByResourceLocator($resourceSegment, $defaults['_environment'], $customUrl->getTargetLocale(), $defaults['_webspace']->getKey()); return ['_controller' => 'SuluWebsiteBundle:Default:redirect', 'url' => $url]; }
/** * {@inheritdoc} */ public function handle($workload) { /** @var PageDocument $document */ $document = $this->documentManager->find($workload['uuid'], $workload['locale']); $urls = $this->webspaceManager->findUrlsByResourceLocator($document->getResourceSegment(), $this->environment, $workload['locale'], $workload['webspaceKey']); foreach ($urls as $url) { $this->client->get($url)->send(); } }
/** * {@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 getSecurityContexts() { $webspaceContexts = []; /* @var Webspace $webspace */ foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { $webspaceContexts[self::getCustomUrlSecurityContext($webspace->getKey())] = [PermissionTypes::VIEW, PermissionTypes::ADD, PermissionTypes::EDIT, PermissionTypes::DELETE]; } return ['Sulu' => ['Webspace Settings' => $webspaceContexts]]; }
/** * {@inheritdoc} */ public function sitemapUrlFunction($url, $locale = null, $webspaceKey = null) { if ($webspaceKey === null) { $webspaceKey = $this->requestAnalyzer->getWebspace()->getKey(); } if ($locale === null) { $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization(); } return $this->webspaceManager->findUrlByResourceLocator($url, $this->environment, $locale, $webspaceKey); }
/** * {@inheritdoc} */ public function process(Request $request, RequestAttributes $requestAttributes) { if (!$request->get('_locale') && !$request->get('_portal')) { return new RequestAttributes(); } $portalInformations = $this->webspaceManager->findPortalInformationsByPortalKeyAndLocale($request->get('_portal'), $request->get('_locale'), $this->environment); if (!$portalInformations) { return new RequestAttributes(); } return new RequestAttributes(['portalInformation' => reset($portalInformations)]); }
/** * {@inheritdoc} */ public function getContentPath($url, $webspaceKey = null, $locale = null, $domain = null) { if ($webspaceKey !== null && $this->requestAnalyzer) { $portalUrls = $this->webspaceManager->findUrlsByResourceLocator($url, $this->environment, $locale ?: $this->requestAnalyzer->getCurrentLocalization()->getLocalization(), $webspaceKey, $domain); if (count($portalUrls) > 0) { return rtrim($portalUrls[0], '/'); } } elseif (strpos($url, '/') === 0 && $this->requestAnalyzer) { return rtrim($this->requestAnalyzer->getResourceLocatorPrefix() . $url, '/'); } return $url; }
/** * {@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(); }
/** * {@inheritdoc} */ public function getSecurityContexts() { $contexts = ['Sulu' => ['Global' => ['sulu.global.snippets' => [PermissionTypes::VIEW, PermissionTypes::ADD, PermissionTypes::EDIT, PermissionTypes::DELETE]]]]; if ($this->defaultEnabled) { $webspaceContexts = []; /* @var Webspace $webspace */ foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { $webspaceContexts[self::getDefaultSnippetsSecurityContext($webspace->getKey())] = [PermissionTypes::VIEW, PermissionTypes::EDIT]; } $contexts['Sulu']['Webspace Settings'] = $webspaceContexts; } return $contexts; }
/** * @param $webspaceKey * * @return WebspaceSitemap */ private function getWebspaceSitemap($webspaceKey) { $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); $webspaceSitemap = new WebspaceSitemap(); $webspaceSitemap->setWebspaceKey($webspace->getKey()); $defaultLocalization = $webspace->getDefaultLocalization(); if ($defaultLocalization) { $webspaceSitemap->setDefaultLocalization($defaultLocalization->getLocalization()); } foreach ($webspace->getAllLocalizations() as $localization) { $webspaceSitemap->addLocalization($localization->getLocalization()); } return $webspaceSitemap; }
/** * {@inheritdoc} */ public function sitemapUrlFunction($url, $locale = null, $webspaceKey = null) { if ($webspaceKey === null) { $webspaceKey = $this->requestAnalyzer->getWebspace()->getKey(); } if ($locale === null) { $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization(); } // FIXME which url or all urls? $portalUrls = $this->webspaceManager->findUrlsByResourceLocator($url, $this->environment, $locale, $webspaceKey); if (sizeof($portalUrls) === 0) { return false; } return rtrim($portalUrls[0], '/'); }
/** * {@inheritdoc} */ public function process(Request $request, RequestAttributes $requestAttributes) { $attributes = []; $attributes['webspaceKey'] = $request->get('webspace'); $attributes['locale'] = $request->get('locale', $request->get('language')); if (empty($attributes['webspaceKey'])) { return new RequestAttributes($attributes); } $attributes['webspace'] = $this->webspaceManager->findWebspaceByKey($attributes['webspaceKey']); if (null === $attributes['locale']) { return new RequestAttributes($attributes); } $attributes['localization'] = $attributes['webspace']->getLocalization($attributes['locale']); return new RequestAttributes($attributes); }
/** * Analyzes the current request, and saves the values for portal, localization and segment for further usage. * * @param Request $request The request to analyze * * @throws Exception\UrlMatchNotFoundException */ public function analyze(Request $request) { $url = $request->getHost() . $request->getPathInfo(); $portalInformation = $this->webspaceManager->findPortalInformationByUrl($url, $this->environment); $this->getParameter = $request->query->all(); $this->postParameter = $request->request->all(); if ($portalInformation === null) { throw new UrlMatchNotFoundException($request->getUri()); } $this->setCurrentMatchType($portalInformation->getType()); $this->setCurrentRedirect($portalInformation->getRedirect()); $this->analyticsKey = $portalInformation->getAnalyticsKey(); if ($portalInformation->getType() == RequestAnalyzerInterface::MATCH_TYPE_REDIRECT) { $this->setCurrentPortalUrl($portalInformation->getUrl()); $this->setCurrentWebspace($portalInformation->getWebspace()); return; } $this->setCurrentPortalUrl($portalInformation->getUrl()); $this->setCurrentLocalization($portalInformation->getLocalization()); $this->setCurrentPortal($portalInformation->getPortal()); $this->setCurrentWebspace($portalInformation->getWebspace()); $this->setCurrentSegment($portalInformation->getSegment()); $request->setLocale($portalInformation->getLocalization()->getLocalization()); list($resourceLocator, $format) = $this->getResourceLocatorFromRequest($portalInformation, $request); // get the path and set it on the request $this->setCurrentResourceLocator($resourceLocator); if ($format) { $request->setRequestFormat($format); } // get the resource locator prefix and set it $this->setCurrentResourceLocatorPrefix(substr($portalInformation->getUrl(), strlen($request->getHost()))); }
/** * {@inheritDoc} */ public function flush() { if (!$this->structuresToInvalidate) { return; } foreach ($this->structuresToInvalidate as $structure) { if (false === $structure->hasTag('sulu.rlp') || null === ($rlp = $structure->getPropertyValueByTagName('sulu.rlp'))) { return; } $urls = $this->webspaceManager->findUrlsByResourceLocator($rlp, $this->environment, $structure->getLanguageCode(), $structure->getWebspaceKey()); foreach ($urls as $url) { $this->proxyClient->purge($url); } } $this->proxyClient->flush(); }
/** * Returns all urls of the given locale which are associated with the given document. * The returned array contains all current urls and all history urls. * The returned urls can contain placeholders (eg {host}). * * @param ResourceSegmentBehavior $document * @param string $locale * * @return array Urls of the given locale which are associated with the given document */ private function getLocaleUrls(ResourceSegmentBehavior $document, $locale) { $documentUuid = $document instanceof UuidBehavior ? $document->getUuid() : null; $webspace = $document instanceof WebspaceBehavior ? $document->getWebspaceName() : null; if (!$locale || !$documentUuid || !$webspace) { return []; } $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspace); // get current resource-locator and history resource-locators $resourceLocators = []; try { $resourceLocators[] = $resourceLocatorStrategy->loadByContentUuid($documentUuid, $webspace, $locale); } catch (ResourceLocatorNotFoundException $e) { // if no resource locator exists there is also no url to purge from the cache } $historyResourceLocators = $resourceLocatorStrategy->loadHistoryByContentUuid($documentUuid, $webspace, $locale); foreach ($historyResourceLocators as $historyResourceLocator) { $resourceLocators[] = $historyResourceLocator->getResourceLocator(); } // get urls for resource-locators $urls = []; foreach ($resourceLocators as $resourceLocator) { $urls = array_merge($urls, $this->webspaceManager->findUrlsByResourceLocator($resourceLocator, $this->environment, $locale, $webspace)); } return $urls; }
/** * Dump given webspace. * * @param Webspace $webspace */ private function dumpWebspace(Webspace $webspace) { foreach ($webspace->getAllLocalizations() as $localization) { $this->output->writeln(sprintf(' - %s (%s)', $webspace->getKey(), $localization->getLocale())); $this->dumpPortalInformations($this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale($webspace->getKey(), $localization->getLocale(), $this->environment)); } }
public function testResolveForPreviewWithRequestParameter() { $this->webspaceManager->getPortalInformations('dev')->willReturn(['sulu.io/de' => []]); $request = new \Symfony\Component\HttpFoundation\Request(['test' => 1], ['test' => 2]); $this->requestStack->getCurrentRequest()->willReturn($request); $result = $this->resolver->resolveForPreview('sulu_io', 'de'); $this->assertEquals(['request' => ['webspaceKey' => 'sulu_io', 'locale' => 'de', 'defaultLocale' => 'de', 'portalUrl' => 'sulu.io/de', 'resourceLocatorPrefix' => '', 'resourceLocator' => '', 'get' => ['test' => 1], 'post' => ['test' => 2], 'analyticsKey' => 'UA-SULU-Test']], $result); }
public function setUp() { parent::setUp(); $this->webspaceManager = $this->prophesize(WebspaceManagerInterface::class); $this->inspector = $this->prophesize(DocumentInspector::class); $this->registry = $this->prophesize(DocumentRegistry::class); $this->document = $this->prophesize(StructureBehavior::class)->willImplement(WebspaceBehavior::class); $this->webspace = $this->prophesize(Webspace::class); $this->localization1 = $this->prophesize(Localization::class); $this->localization2 = $this->prophesize(Localization::class); $this->subscriber = new FallbackLocalizationSubscriber($this->encoder->reveal(), $this->inspector->reveal(), $this->registry->reveal(), new LocalizationFinder($this->webspaceManager->reveal())); $this->hydrateEvent->getNode()->willReturn($this->node->reveal()); $this->hydrateEvent->getDocument()->willReturn($this->document->reveal()); $this->hydrateEvent->getLocale()->willReturn(self::FIX_LOCALE); $this->webspaceManager->findWebspaceByKey(self::FIX_WEBSPACE)->willReturn($this->webspace); $this->registry->getDefaultLocale()->willReturn('de'); }
/** * Return the default structure for the given StructureBehavior implementing document. * * @param StructureBehavior $document * * @return string */ private function getDefaultStructureType(StructureBehavior $document) { $alias = $this->inspector->getMetadata($document)->getAlias(); $webspace = $this->webspaceManager->findWebspaceByKey($this->inspector->getWebspace($document)); if (!$webspace) { return $this->getDefaultStructureTypeFromConfig($alias); } return $webspace->getDefaultTemplate($alias); }