/** * {@inheritdoc} */ public function save(ResourceSegmentBehavior $document) { $path = $document->getResourceSegment(); $webspaceKey = $this->documentInspector->getWebspace($document); $locale = $this->documentInspector->getLocale($document); $segmentKey = null; $webspaceRouteRootPath = $this->getWebspaceRouteNodeBasePath($webspaceKey, $locale, $segmentKey); try { $routeNodePath = $this->loadByContent($this->documentInspector->getNode($document), $webspaceKey, $locale, $segmentKey); $routeDocument = $this->documentManager->find($webspaceRouteRootPath . $routeNodePath, $locale, ['rehydrate' => false]); $routeDocumentPath = $webspaceRouteRootPath . $routeNodePath; } catch (ResourceLocatorNotFoundException $e) { $routeDocument = $this->documentManager->create('route'); $routeDocumentPath = $webspaceRouteRootPath . $path; } $routeDocument->setTargetDocument($document); try { $this->documentManager->persist($routeDocument, $locale, ['path' => $routeDocumentPath, 'auto_create' => true, 'override' => true]); $this->documentManager->publish($routeDocument, $locale); } catch (ItemExistsException $e) { throw new ResourceLocatorAlreadyExistsException($document->getResourceSegment(), $routeDocumentPath); } }
/** * 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; }
/** * Sets the ResourceSegment to the given property of the given document. * * @param ResourceSegmentBehavior $document * @param PropertyMetadata $property */ private function persistDocument(ResourceSegmentBehavior $document, PropertyMetadata $property) { $document->getStructure()->getProperty($property->getName())->setValue($document->getResourceSegment()); }
/** * {@inheritdoc} */ public function save(ResourceSegmentBehavior $document, $userId) { $path = $document->getResourceSegment(); $webspaceKey = $this->documentInspector->getWebspace($document); $languageCode = $this->documentInspector->getLocale($document); try { $treeValue = $this->loadByContent($document); } catch (ResourceLocatorNotFoundException $e) { $treeValue = null; } if ($treeValue === $path) { return false; } if (!$this->isValid($path, $webspaceKey, $languageCode)) { throw new ResourceLocatorNotValidException($path); } if (!$this->mapper->unique($path, $webspaceKey, $languageCode)) { try { $treeContent = $this->loadByResourceLocator($path, $webspaceKey, $languageCode); // FIXME Required because jackalope-doctrine-dbal does not return references which only exist in the current // session. If it would loadByContent would already return some value, which would make this check obsolete. if ($treeContent === $this->documentInspector->getUuid($document)) { return false; } throw new ResourceLocatorAlreadyExistsException($path, $treeContent); } catch (ResourceLocatorNotFoundException $exception) { // a node exists but is not a resource-locator. } } $this->mapper->save($document); }