예제 #1
0
 /**
  * Create route-document for given domain.
  *
  * @param string $domain
  * @param CustomUrlBehavior $document
  * @param Localization $locale
  * @param string $persistedLocale
  * @param string $routesPath
  *
  * @return RouteDocument
  *
  * @throws ResourceLocatorAlreadyExistsException
  */
 protected function createRoute($domain, CustomUrlBehavior $document, Localization $locale, $persistedLocale, $routesPath)
 {
     $path = sprintf('%s/%s', $routesPath, $domain);
     $routeDocument = $this->findOrCreateRoute($path, $persistedLocale, $document, $domain);
     $routeDocument->setTargetDocument($document);
     $routeDocument->setLocale($locale->getLocalization());
     $routeDocument->setHistory(false);
     $this->documentManager->persist($routeDocument, $persistedLocale, ['path' => $path, 'auto_create' => true]);
     $this->documentManager->publish($routeDocument, $persistedLocale);
     return $routeDocument;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function save($uuid, array $data, $locale = null)
 {
     $document = $this->find($uuid, $locale);
     $this->bind($document, $data, $locale);
     try {
         $this->documentManager->persist($document, $locale, ['parent_path' => PathHelper::getParentPath($document->getPath()), 'load_ghost_content' => true, 'auto_rename' => false, 'auto_name_locale' => $locale]);
         $this->documentManager->publish($document, $locale);
     } catch (NodeNameAlreadyExistsException $ex) {
         throw new TitleAlreadyExistsException($document->getTitle());
     }
     return $document;
 }
예제 #3
0
파일: PhpcrMapper.php 프로젝트: sulu/sulu
 /**
  * {@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);
     }
 }
예제 #4
0
 /**
  * Changes the old route to a history route and redirect to the new route.
  *
  * @param RouteBehavior $oldDocument
  * @param RouteBehavior $newDocument
  */
 private function changeOldPathToHistoryRoutes(RouteBehavior $oldDocument, RouteBehavior $newDocument)
 {
     $oldDocument->setTargetDocument($newDocument);
     $oldDocument->setHistory(true);
     $oldRouteNode = $this->documentInspector->getNode($oldDocument);
     $oldRouteNode->setProperty(self::NODE_HISTORY_FIELD, true);
     foreach ($this->documentInspector->getReferrers($oldDocument) as $referrer) {
         if ($referrer instanceof RouteBehavior) {
             $referrer->setTargetDocument($newDocument);
             $referrer->setHistory(true);
             $this->documentManager->persist($referrer, null, ['path' => $this->documentInspector->getPath($referrer)]);
             $this->documentManager->publish($referrer, null);
         }
     }
 }
예제 #5
0
 private function initializeWebspace(OutputInterface $output, Webspace $webspace)
 {
     $homePath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%content%']);
     $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%route%']);
     $webspaceLocales = [];
     foreach ($webspace->getAllLocalizations() as $localization) {
         $webspaceLocales[] = $localization->getLocale();
     }
     $homeType = $webspace->getDefaultTemplate('home');
     $existingLocales = [];
     $homeDocument = null;
     if ($this->nodeManager->has($homePath)) {
         $homeDocument = $this->documentManager->find($homePath, null, ['load_ghost_content' => false, 'auto_create' => true, 'path' => $homePath]);
         $existingLocales = $this->inspector->getLocales($homeDocument);
     }
     foreach ($webspaceLocales as $webspaceLocale) {
         if (in_array($webspaceLocale, $existingLocales)) {
             $output->writeln(sprintf('  [ ] <info>homepage</info>: %s (%s)', $homePath, $webspaceLocale));
             continue;
         }
         $output->writeln(sprintf('  [+] <info>homepage</info>: [%s] %s (%s)', $homeType, $homePath, $webspaceLocale));
         $persistOptions = ['ignore_required' => true];
         if (!$homeDocument) {
             $homeDocument = new HomeDocument();
             $persistOptions['path'] = $homePath;
             $persistOptions['auto_create'] = true;
         } else {
             $homeDocument = $this->documentManager->find($homePath, $webspaceLocale, ['load_ghost_content' => false]);
         }
         $homeDocument->setTitle('Homepage');
         $homeDocument->setStructureType($homeType);
         $this->documentManager->persist($homeDocument, $webspaceLocale, $persistOptions);
         $this->documentManager->publish($homeDocument, $webspaceLocale);
         $routePath = $routesPath . '/' . $webspaceLocale;
         try {
             $routeDocument = $this->documentManager->find($routePath);
         } catch (DocumentNotFoundException $e) {
             $routeDocument = $this->documentManager->create('route');
         }
         $routeDocument->setTargetDocument($homeDocument);
         $this->documentManager->persist($routeDocument, $webspaceLocale, ['path' => $routePath, 'auto_create' => true]);
         $this->documentManager->publish($routeDocument, $webspaceLocale);
     }
     $this->documentManager->flush();
 }