/** * {@inheritdoc} */ public function setPermissions($type, $identifier, $permissions) { $document = $this->documentManager->find($identifier, null, ['rehydrate' => false]); $document->setPermissions($permissions); $this->documentManager->persist($document); $this->documentManager->flush(); }
public function testSetPermissions() { $document = $this->prophesize(WebspaceBehavior::class); $document->willImplement(SecurityBehavior::class); $this->documentManager->find('1', null, ['rehydrate' => false])->willReturn($document); $document->setPermissions(['role' => ['view']])->shouldBeCalled(); $this->documentManager->persist($document)->shouldBeCalled(); $this->documentManager->flush()->shouldBeCalled(); $this->phpcrAccessControlProvider->setPermissions(get_class($document), '1', ['role' => ['view' => true, 'edit' => false]]); }
/** * {@inheritdoc} */ public function setPermissions($type, $identifier, $permissions) { $allowedPermissions = []; foreach ($permissions as $roleId => $rolePermissions) { $allowedPermissions[$roleId] = $this->getAllowedPermissions($rolePermissions); } $document = $this->documentManager->find($identifier, null, ['rehydrate' => false]); $document->setPermissions($allowedPermissions); $this->documentManager->persist($document); $this->documentManager->flush(); }
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; }
private function createPage() { $page = new PageDocument(); $page->setTitle('Hello'); $page->setResourceSegment('/hello'); $page->setParent($this->contentDocument); $page->setStructureType('internallinks'); $page->getStructure()->bind(['title' => 'World', 'internalLinks' => [$this->contentDocument->getUuid()]], true); $this->documentManager->persist($page, 'fr'); $this->documentManager->flush(); return $page; }
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; }
/** * @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); } }
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(); }
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(); }
/** * It can deserialize persisted documents with routes. */ public function testDeserializationPersisted() { $page = $this->createPage(['title' => 'Hello']); $this->manager->persist($page, 'de'); $this->manager->flush(); $result = $this->serializer->serialize($page, 'json'); $page = $this->serializer->deserialize($result, PageDocument::class, 'json'); $this->assertInstanceOf(PageDocument::class, $page); $this->assertEquals('Hello', $page->getStructure()->getProperty('title')->getValue()); $this->assertEquals('de', $this->registry->getOriginalLocaleForDocument($page)); }
/** * 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; }
/** * {@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; }
/** * Upgrades the node to new URL representation. * * @param NodeInterface $node The node to be upgraded * @param string $locale The locale of the node to be upgraded * @param array $properties The properties which are or contain URL fields * @param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise */ private function upgradeNode(NodeInterface $node, $locale, $properties, $addScheme) { /** @var BasePageDocument $document */ $document = $this->documentManager->find($node->getIdentifier(), $locale); $documentLocales = $this->documentInspector->getLocales($document); if (!in_array($locale, $documentLocales)) { return; } foreach ($properties as $property) { $this->upgradeProperty($document->getStructure()->getProperty($property), $addScheme); } $this->documentManager->persist($document, $locale); }
/** * {@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; }
/** * 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); } } }
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']); }
/** * @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; }
/** * Upgrades the node to new date representation. * * @param NodeInterface $node The node to be upgraded * @param string $locale The locale of the node to be upgraded * @param array $properties The properties which are or contain date fields * @param bool $up */ private function upgradeNode(NodeInterface $node, $locale, array $properties, $up) { /** @var BasePageDocument $document */ $document = $this->documentManager->find($node->getIdentifier(), $locale); $documentLocales = $this->documentInspector->getLocales($document); if (!in_array($locale, $documentLocales)) { return; } foreach ($properties as $property) { if ($property['property'] instanceof BlockMetadata) { $this->upgradeBlockProperty($property['property'], $property['components'], $node, $locale, $up); } else { $this->upgradeProperty($property['property'], $node, $locale, $up); } } $this->documentManager->persist($document, $locale, ['auto_name' => false]); }
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(); }
/** * Upgrades the node to new URL representation. * * @param NodeInterface $node The node to be upgraded * @param string $locale The locale of the node to be upgraded * @param array $properties The properties which are or contain URL fields * @param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise */ private function upgradeNode(NodeInterface $node, $locale, array $properties, $addScheme) { /** @var BasePageDocument $document */ $document = $this->documentManager->find($node->getIdentifier(), $locale); $documentLocales = $this->documentInspector->getLocales($document); if (!in_array($locale, $documentLocales)) { return; } foreach ($properties as $property) { $propertyValue = $document->getStructure()->getProperty($property['property']->getName()); if ($property['property'] instanceof BlockMetadata) { $this->upgradeBlockProperty($property['property'], $property['components'], $propertyValue, $addScheme); } else { $this->upgradeProperty($propertyValue, $addScheme); } } $this->documentManager->persist($document, $locale); }
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); }