示例#1
0
 public function indexDocument($title, $url)
 {
     /* @var ContentMapperInterface $mapper */
     $document = $this->documentManager->create('page');
     $document->setTitle($title);
     $document->setStructureType('default');
     $document->setParent($this->homeDocument);
     $document->setResourceSegment($url);
     $this->documentManager->persist($document, 'de');
     return $document;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function create($webspaceKey, array $data, $locale = null)
 {
     $document = $this->documentManager->create('custom_url');
     $this->bind($document, $data, $locale);
     try {
         $this->documentManager->persist($document, $locale, ['parent_path' => $this->getItemsPath($webspaceKey), 'load_ghost_content' => true, 'auto_rename' => false]);
         $this->documentManager->publish($document, $locale);
     } catch (NodeNameAlreadyExistsException $ex) {
         throw new TitleAlreadyExistsException($document->getTitle());
     }
     return $document;
 }
示例#3
0
 public function indexDocument($title, $url)
 {
     /* @var ContentMapperInterface $mapper */
     $document = $this->documentManager->create('page');
     $document->setTitle($title);
     $document->setStructureType('default');
     $document->setParent($this->homeDocument);
     $document->setResourceSegment($url);
     $webspaceReflection = new \ReflectionProperty(PageDocument::class, 'webspaceName');
     $webspaceReflection->setAccessible(true);
     $webspaceReflection->setValue($document, 'sulu_io');
     $this->documentManager->persist($document, 'de');
     return $document;
 }
示例#4
0
 /**
  * Updates the route for the given document and creates history routes if necessary.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof RouteBehavior) {
         return;
     }
     $node = $event->getNode();
     $node->setProperty(self::NODE_HISTORY_FIELD, $document->isHistory());
     $targetDocument = $document->getTargetDocument();
     if ($targetDocument instanceof HomeDocument || !$targetDocument instanceof WebspaceBehavior || !$targetDocument instanceof ResourceSegmentBehavior) {
         return;
     }
     // copy new route to old position
     $webspaceKey = $targetDocument->getWebspaceName();
     $locale = $this->documentInspector->getLocale($document);
     $routePath = $this->sessionManager->getRoutePath($webspaceKey, $locale, null) . $targetDocument->getResourceSegment();
     // create a route node if it is not a new document and the path changed
     $documentPath = $this->documentInspector->getPath($document);
     if ($documentPath && $documentPath != $routePath) {
         /** @var RouteDocument $newRouteDocument */
         $newRouteDocument = $this->documentManager->create('route');
         $newRouteDocument->setTargetDocument($targetDocument);
         $this->documentManager->persist($newRouteDocument, $locale, ['path' => $routePath, 'auto_create' => true]);
         $this->documentManager->publish($newRouteDocument, $locale);
         // change routes in old position to history
         $this->changeOldPathToHistoryRoutes($document, $newRouteDocument);
     }
 }
示例#5
0
 private function loadFixtures()
 {
     // HOTELS
     $this->hotel1 = $this->documentManager->create('snippet');
     $this->hotel1->setStructureType('hotel');
     $this->hotel1->setTitle('Le grande budapest');
     $this->documentManager->persist($this->hotel1, 'de');
     $this->hotel2 = $this->documentManager->create('snippet');
     $this->hotel2->setStructureType('hotel');
     $this->hotel2->setTitle('L\'Hôtel New Hampshire');
     $this->documentManager->persist($this->hotel2, 'de');
     // CARS
     $car = $this->documentManager->create('snippet');
     $car->setStructureType('car');
     $car->setTitle('Skoda');
     $this->documentManager->persist($car, 'de');
     $car = $this->documentManager->create('snippet');
     $car->setStructureType('car');
     $car->setTitle('Volvo');
     $this->documentManager->persist($car, 'de');
     $car = $this->documentManager->create('snippet');
     $car->setStructureType('car');
     $car->setTitle('Ford');
     $this->documentManager->persist($car, 'de');
     $car = $this->documentManager->create('snippet');
     $car->setStructureType('car');
     $car->setTitle('VW');
     $this->documentManager->persist($car, 'en');
     $this->documentManager->flush();
 }
 /**
  * @dataProvider provideRemoveSnippetWithReferencesDereference
  */
 public function testRemoveSnippetWithReferencesDereference($multiple = false)
 {
     $document = $this->documentManager->create('page');
     $document->setTitle('test');
     $document->setResourceSegment('/url/foo');
     if ($multiple) {
         $document->getStructure()->bind(['animals' => [$this->snippet1->getUuid(), $this->snippet2->getUuid()]], false);
     } else {
         $document->getStructure()->bind(['animals' => $this->snippet1->getUuid()], false);
     }
     $document->setParent($this->parent);
     $document->setStructureType('test_page');
     $this->documentManager->persist($document, 'de');
     $this->documentManager->flush();
     $this->contentMapper->delete($this->snippet1->getUuid(), 'sulu_io', true);
     try {
         $this->session->getNode($this->snippet1OriginalPath);
         $this->assertTrue(false, 'Snippet was found FAIL');
     } catch (\PHPCR\PathNotFoundException $e) {
         $this->assertTrue(true, 'Snippet was removed');
     }
     $referrer = $this->documentManager->find('/cmf/sulu_io/contents/test', 'de');
     if ($multiple) {
         $contents = $referrer->getStructure()->getProperty('animals')->getValue();
         $this->assertCount(1, $contents);
         $content = reset($contents);
         $this->assertEquals($this->snippet2->getUuid(), $content);
     } else {
         $contents = $referrer->getStructure()->getProperty('animals')->getValue();
         $this->assertCount(0, $contents);
     }
 }
示例#7
0
 public function testIndexNoMedia()
 {
     $document = $this->documentManager->create('page');
     $document->setStructureType('images');
     $document->setTitle('Hallo');
     $document->setResourceSegment('/hallo');
     $document->setParent($this->webspaceDocument);
     $this->documentManager->persist($document, 'de');
     $this->documentManager->flush();
 }
示例#8
0
 /**
  * Find or create route-document for given path.
  *
  * @param string $path
  * @param string $locale
  * @param CustomUrlBehavior $document
  * @param string $route
  *
  * @return RouteDocument
  *
  * @throws ResourceLocatorAlreadyExistsException
  */
 protected function findOrCreateRoute($path, $locale, CustomUrlBehavior $document, $route)
 {
     try {
         /** @var RouteDocument $routeDocument */
         $routeDocument = $this->documentManager->find($path, $locale);
     } catch (DocumentNotFoundException $ex) {
         return $this->documentManager->create('custom_url_route');
     }
     if (!$routeDocument instanceof RouteDocument || $routeDocument->getTargetDocument()->getUuid() !== $document->getUuid()) {
         throw new ResourceLocatorAlreadyExistsException($route, $document->getTitle());
     }
     return $routeDocument;
 }
示例#9
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);
     }
 }
 /**
  * @param $template
  * @param $data
  * @param $parent
  *
  * @return PageDocument
  */
 private function savePage($template, $data, $parent, $tags = [])
 {
     $data = array_merge(['structureType' => $template, 'parent' => $parent, 'workflowStage' => 2, 'webspace_key' => 'sulu_io'], $data);
     $document = $this->documentManager->create('page');
     $options = ['csrf_protection' => false, 'webspace_key' => 'sulu_io'];
     $form = $this->formFactory->create('page', $document, $options);
     $clearMissing = false;
     $form->submit($data, $clearMissing);
     $this->documentManager->persist($document, 'en', ['user' => 1]);
     $this->documentManager->flush();
     $node = $this->inspector->getNode($document);
     $node->setProperty('i18n:en-excerpt-tags', $tags);
     $node->getSession()->save();
     return $document;
 }
示例#11
0
 public function testGetExternalLink()
 {
     $client = $this->createAuthenticatedClient();
     $externalLinkPage = $this->documentManager->create('page');
     $externalLinkPage->setTitle('page');
     $externalLinkPage->setStructureType('external-link');
     $externalLinkPage->setRedirectType(RedirectType::EXTERNAL);
     $externalLinkPage->setRedirectExternal('http://www.sulu.io');
     $externalLinkPage->setResourceSegment('/test');
     $this->documentManager->persist($externalLinkPage, 'en', ['parent_path' => '/cmf/sulu_io/contents']);
     $this->documentManager->flush();
     $client->request('GET', '/api/nodes/' . $externalLinkPage->getUuid() . '?webspace=sulu_io&language=en');
     $response = json_decode($client->getResponse()->getContent(), true);
     $this->assertEquals('external', $response['linked']);
     $this->assertEquals('http://www.sulu.io', $response['external']);
 }
示例#12
0
 /**
  * @param string $title
  * @param string $locale
  * @param string $link
  *
  * @return PageDocument
  */
 private function createExternalLinkPage($title, $locale, $link)
 {
     $data['title'] = $title;
     $data['url'] = '/' . $title;
     /** @var PageDocument $document */
     $document = $this->documentManager->create('page');
     $document->setStructureType('simple');
     $document->setTitle($title);
     $document->setResourceSegment($data['url']);
     $document->setLocale($locale);
     $document->setRedirectType(RedirectType::EXTERNAL);
     $document->setRedirectExternal($link);
     $document->getStructure()->bind($data);
     $this->documentManager->persist($document, $locale, ['path' => $this->sessionManager->getContentPath('sulu_io') . '/' . $title, 'auto_create' => true]);
     $this->documentManager->flush();
     return $document;
 }
示例#13
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();
 }
示例#14
0
 public function testGetWithPermissions()
 {
     // create secured page
     $securedPage = $this->documentManager->create('page');
     $securedPage->setTitle('secured');
     $securedPage->setResourceSegment('/secured');
     $securedPage->setStructureType('default');
     $this->documentManager->persist($securedPage, 'en', ['parent_path' => '/cmf/sulu_io/contents']);
     $this->documentManager->flush();
     $this->documentManager->clear();
     $client = $this->createAuthenticatedClient();
     $client->request('GET', '/api/nodes?uuid=' . $securedPage->getUuid() . '&tree=true&webspace=sulu_io&language=en');
     $response = json_decode($client->getResponse()->getContent(), true);
     $this->assertArrayHasKey('_permissions', $response['_embedded']['nodes'][0]['_embedded'][0]);
     $client->request('GET', '/api/nodes/' . $securedPage->getUuid() . '?language=en&webspace=sulu_io');
     $response = json_decode($client->getResponse()->getContent(), true);
     $this->assertArrayHasKey('_permissions', $response);
 }