/** * {@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(); }
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 generateDocumentIndex($count, $urlPrefix = '/test-') { $documents = []; for ($i = 1; $i <= $count; ++$i) { $pageDocument = new PageDocument(); $pageDocument->setStructureType('default'); $pageDocument->setParent($this->homeDocument); $pageDocument->setTitle('Document Title ' . $i); $pageDocument->setWorkflowStage(WorkflowStage::PUBLISHED); $pageDocument->setResourceSegment($urlPrefix . $i); $this->documentManager->persist($pageDocument, 'de'); $documents[] = $pageDocument; } $this->documentManager->flush(); return $documents; }
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); } }
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)); }
/** * Structures are updated according to their xml definition. * * @param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise */ private function iterateStructures($addScheme) { $properties = []; // find templates containing URL fields $structureMetadatas = array_merge($this->structureMetadataFactory->getStructures('page'), $this->structureMetadataFactory->getStructures('snippet')); $structureMetadatas = array_filter($structureMetadatas, function (StructureMetadata $structureMetadata) use(&$properties) { $structureName = $structureMetadata->getName(); $this->findUrlProperties($structureMetadata, $properties); return !empty($properties[$structureName]) || !empty($blockProperties[$structureName]); }); foreach ($structureMetadatas as $structureMetadata) { $this->iterateStructureNodes($structureMetadata, $properties[$structureMetadata->getName()], $addScheme); } $this->documentManager->flush(); }
/** * @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; }
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; }
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(); }
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); }