示例#1
0
 /**
  * Return snippets identified by the given UUIDs.
  *
  * UUIDs which fail to resolve to a snippet will be ignored.
  *
  * @param array  $uuids
  * @param string $locale
  * @param bool $loadGhostContent
  *
  * @return SnippetDocument
  */
 public function getSnippetsByUuids(array $uuids, $locale, $loadGhostContent = false)
 {
     $snippets = [];
     foreach ($uuids as $uuid) {
         try {
             $snippet = $this->documentManager->find($uuid, $locale, ['load_ghost_content' => $loadGhostContent]);
             $snippets[] = $snippet;
         } catch (DocumentNotFoundException $e) {
             // ignore not found items
         }
     }
     return $snippets;
 }
示例#2
0
 /**
  * Set the document parent to be the webspace content path
  * when the document has no parent.
  *
  * @param FormEvent $event
  */
 public function postSubmitDocumentParent(FormEvent $event)
 {
     $document = $event->getData();
     if ($document->getParent()) {
         return;
     }
     $form = $event->getForm();
     $webspaceKey = $form->getConfig()->getAttribute('webspace_key');
     $parent = $this->documentManager->find($this->sessionManager->getContentPath($webspaceKey));
     if (null === $parent) {
         throw new \InvalidArgumentException(sprintf('Could not determine parent for document with title "%s" in webspace "%s"', $document->getTitle(), $webspaceKey));
     }
     $document->setParent($parent);
 }
示例#3
0
 /**
  * Prefix url of document with current resourcelocator prefix.
  *
  * @param IndexRebuildEvent $event
  */
 public function onIndexRebuild(IndexRebuildEvent $event)
 {
     $output = $event->getOutput();
     $purge = $event->getPurge();
     $filter = $event->getFilter();
     $output->writeln('<info>Rebuilding content index</info>');
     // TODO: We cannot select all contents via. the parent type, see: https://github.com/jackalope/jackalope-doctrine-dbal/issues/217
     $query = $this->documentManager->createQuery('SELECT * FROM [nt:unstructured] AS a WHERE [jcr:mixinTypes] = "sulu:page" or [jcr:mixinTypes] = "sulu:snippet"');
     $count = [];
     if ($purge) {
         $this->purgeContentIndexes($output);
     }
     $documents = $query->execute();
     $progress = new ProgressHelper();
     $progress->start($output, count($documents));
     foreach ($documents as $document) {
         $locales = $this->inspector->getLocales($document);
         foreach ($locales as $locale) {
             try {
                 $this->documentManager->find($document->getUuid(), $locale);
                 $documentClass = get_class($document);
                 if ($filter && !preg_match('{' . $filter . '}', $documentClass)) {
                     continue;
                 }
                 $this->searchManager->index($document, $locale);
                 if (!isset($count[$documentClass])) {
                     $count[$documentClass] = 0;
                 }
                 ++$count[$documentClass];
             } catch (\Exception $e) {
                 $output->writeln(sprintf('<error>Error indexing or de-indexing page (path: %s locale: %s)</error>: %s', $this->inspector->getPath($document), $locale, $e->getMessage()));
             }
         }
         $progress->advance();
     }
     $output->writeln('');
     foreach ($count as $className => $count) {
         if ($count == 0) {
             continue;
         }
         $output->writeln(sprintf('<comment>Content</comment>: %s <info>%s</info> indexed', $className, $count));
     }
 }
 public function testRun()
 {
     $this->initPhpcr();
     $snippet = $this->documentManager->create('snippet');
     $snippet->setStructureType('car');
     $snippet->setTitle('Hallo');
     $snippet->getStructure()->bind(['description' => 'This is a perfect description.']);
     $this->documentManager->persist($snippet, 'en', ['parent_path' => '/cmf/snippets/car']);
     $this->documentManager->flush();
     $this->tester->execute(['srcLocale' => 'en', 'destLocale' => 'de']);
     $output = $this->tester->getDisplay();
     $this->assertContains('Done', $output);
     $this->documentRegistry->clear();
     $resultEN = $this->documentManager->find($snippet->getUuid(), 'en');
     $resultDE = $this->documentManager->find($snippet->getUuid(), 'de');
     $this->assertEquals('Hallo', $resultDE->getTitle());
     $this->assertEquals('Hallo', $resultEN->getTitle());
     $this->assertEquals('This is a perfect description.', $resultDE->getStructure()->getProperty('description')->getValue());
     $this->assertEquals('This is a perfect description.', $resultEN->getStructure()->getProperty('description')->getValue());
 }
示例#5
0
文件: Webspace.php 项目: sulu/sulu
 /**
  * Returns a array of the given content data of the document.
  *
  * @param BasePageDocument $document
  * @param $locale
  * @param $format
  *
  * @return array
  */
 protected function getContentData(BasePageDocument $document, $locale, $format)
 {
     /** @var BasePageDocument $loadedDocument */
     $loadedDocument = $this->documentManager->find($document->getUuid(), $locale);
     /** @var \Sulu\Component\Content\Metadata\StructureMetadata $metaData */
     $metaData = $this->documentInspector->getStructureMetadata($document);
     $propertyValues = $loadedDocument->getStructure()->toArray();
     $properties = $metaData->getProperties();
     $contentData = $this->getPropertiesContentData($properties, $propertyValues, $format);
     return $contentData;
 }
 /**
  * It should set the parent document.
  */
 public function testSetParentDocument()
 {
     $this->persistEvent->getDocument()->willReturn($this->document->reveal());
     $this->persistEvent->getLocale()->willReturn('fr');
     $this->metadataFactory->getMetadataForClass(get_class($this->document->reveal()))->willReturn($this->metadata->reveal());
     $this->metadata->getAlias()->willReturn('test');
     $this->nodeManager->createPath('/')->willReturn($this->parentNode->reveal());
     $this->persistEvent->hasParentNode()->shouldBeCalled();
     $this->persistEvent->setParentNode($this->parentNode->reveal())->shouldBeCalled();
     $this->documentManager->find('/test', 'fr')->willReturn($this->parentDocument);
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }
示例#7
0
 /**
  * Prefix url of document with current resourcelocator prefix.
  *
  * @param IndexRebuildEvent $event
  */
 public function onIndexRebuild(IndexRebuildEvent $event)
 {
     $output = $event->getOutput();
     $filter = $event->getFilter();
     $output->writeln('<info>Rebuilding content index</info>');
     $typeMap = $this->baseMetadataFactory->getPhpcrTypeMap();
     $phpcrTypes = [];
     foreach ($typeMap as $type) {
         $phpcrType = $type['phpcr_type'];
         if ($phpcrType !== 'sulu:path') {
             $phpcrTypes[] = sprintf('[jcr:mixinTypes] = "%s"', $phpcrType);
         }
     }
     $condition = implode(' or ', $phpcrTypes);
     // TODO: We cannot select all contents via. the parent type, see: https://github.com/jackalope/jackalope-doctrine-dbal/issues/217
     $query = $this->documentManager->createQuery('SELECT * FROM [nt:unstructured] AS a WHERE ' . $condition);
     $count = [];
     $documents = $query->execute();
     $progress = new ProgressHelper();
     $progress->start($output, count($documents));
     foreach ($documents as $document) {
         if ($document instanceof SecurityBehavior && !empty($document->getPermissions())) {
             $progress->advance();
             continue;
         }
         $locales = $this->inspector->getLocales($document);
         foreach ($locales as $locale) {
             try {
                 $this->documentManager->find($document->getUuid(), $locale);
                 $documentClass = get_class($document);
                 if ($filter && !preg_match('{' . $filter . '}', $documentClass)) {
                     continue;
                 }
                 $this->searchManager->index($document, $locale);
                 if (!isset($count[$documentClass])) {
                     $count[$documentClass] = 0;
                 }
                 ++$count[$documentClass];
             } catch (\Exception $e) {
                 $output->writeln(sprintf('<error>Error indexing or de-indexing page (path: %s locale: %s)</error>: %s', $this->inspector->getPath($document), $locale, $e->getMessage()));
             }
         }
         $progress->advance();
     }
     $output->writeln('');
     foreach ($count as $className => $count) {
         if ($count == 0) {
             continue;
         }
         $output->writeln(sprintf('<comment>Content</comment>: %s <info>%s</info> indexed', $className, $count));
     }
 }
 public function testRun()
 {
     $this->initPhpcr();
     $page = $this->documentManager->create('page');
     $page->setStructureType('default');
     $page->setTitle('Hallo');
     $page->getStructure()->bind(['article' => 'This is a perfect description.']);
     $page->setResourceSegment('/hallo');
     $this->documentManager->persist($page, 'de', ['parent_path' => '/cmf/sulu_io/contents']);
     $this->documentManager->flush();
     $this->tester->execute(['webspaceKey' => 'sulu_io', 'srcLocale' => 'de', 'destLocale' => 'en']);
     $output = $this->tester->getDisplay();
     $this->assertContains('Done', $output);
     $this->documentRegistry->clear();
     $resultEN = $this->documentManager->find($page->getUuid(), 'en');
     $resultDE = $this->documentManager->find($page->getUuid(), 'de');
     $this->assertEquals('Hallo', $resultDE->getTitle());
     $this->assertEquals('Hallo', $resultEN->getTitle());
     $this->assertEquals('This is a perfect description.', $resultDE->getStructure()->getProperty('article')->getValue());
     $this->assertEquals('This is a perfect description.', $resultEN->getStructure()->getProperty('article')->getValue());
     $this->assertEquals('/hallo', $resultDE->getResourceSegment());
     $this->assertEquals('/hallo', $resultEN->getResourceSegment());
 }
示例#9
0
 public function testOnIndexRebuild()
 {
     $event = $this->prophesize(IndexRebuildEvent::class);
     $query = $this->prophesize(Query::class);
     $document = $this->prophesize(StructureBehavior::class);
     $document->willImplement(UuidBehavior::class);
     $securableDocument = $this->prophesize(StructureBehavior::class);
     $securableDocument->willImplement(SecurityBehavior::class);
     $securableDocument->willImplement(UuidBehavior::class);
     $securableDocument->getPermissions()->willReturn([]);
     $securedDocument = $this->prophesize(StructureBehavior::class);
     $securedDocument->willImplement(SecurityBehavior::class);
     $securedDocument->willImplement(UuidBehavior::class);
     $securedDocument->getPermissions()->willReturn(['some' => 'permissions']);
     $typemap = [['phpcr_type' => 'page'], ['phpcr_type' => 'home'], ['phpcr_type' => 'snippet']];
     $output = $this->prophesize(OutputInterface::class);
     $event->getOutput()->willReturn($output->reveal());
     $event->getFilter()->shouldBeCalled();
     $this->baseMetadataFactory->getPhpcrTypeMap()->shouldBeCalled()->willReturn($typemap);
     $this->documentManager->createQuery('SELECT * FROM [nt:unstructured] AS a WHERE [jcr:mixinTypes] = "page" or [jcr:mixinTypes] = "home" or [jcr:mixinTypes] = "snippet"')->shouldBeCalled()->willReturn($query->reveal());
     $query->execute()->shouldBeCalled()->willReturn([$document->reveal(), $securableDocument->reveal(), $securedDocument->reveal()]);
     $this->inspector->getLocales($document->reveal())->shouldBeCalled()->willReturn(['de', 'en']);
     $document->getUuid()->shouldBeCalled()->willReturn('1');
     $this->documentManager->find('1', 'en')->shouldBeCalled();
     $this->searchManager->index($document->reveal(), 'en')->shouldBeCalled();
     $this->documentManager->find('1', 'de')->shouldBeCalled();
     $this->searchManager->index($document->reveal(), 'de')->shouldBeCalled();
     $this->inspector->getLocales($securableDocument->reveal())->shouldBeCalled()->willReturn(['de']);
     $securableDocument->getUuid()->willReturn('2');
     $this->documentManager->find('2', 'de')->shouldBeCalled();
     $this->searchManager->index($securableDocument->reveal(), 'de')->shouldBeCalled();
     $securedDocument->getUuid()->willReturn('3');
     $this->documentManager->find('3', 'de')->shouldNotBeCalled();
     $this->searchManager->index($securedDocument->reveal(), 'de')->shouldNotBeCalled();
     $this->reindexListener->onIndexRebuild($event->reveal());
 }
示例#10
0
文件: Webspace.php 项目: sulu/sulu
 /**
  * Prepare the settings value for the respective setter.
  *
  * @param $key
  * @param $value
  *
  * @return mixed|object
  */
 protected function getSetterValue($key, $value)
 {
     if (empty($value)) {
         return;
     }
     switch ($key) {
         case 'redirectTarget':
             $value = $this->documentManager->find($value);
             break;
         case 'permissions':
             $value = json_decode($value, true);
             break;
         case 'navigationContexts':
             $value = json_decode($value);
             break;
     }
     return $value;
 }
示例#11
0
 public function testOrderAtInternalLink()
 {
     $this->tokenStorage->setToken($this->createUserTokenWithId(17));
     $data = $this->prepareOrderAtData();
     $this->documentManager->clear();
     $testSiteData = ['title' => 'Test', 'nodeType' => Structure::NODE_TYPE_INTERNAL_LINK, 'url' => '/test/123', 'internal_link' => $data[0]->getUuid()];
     $site = $this->mapper->save($testSiteData, 'internal_link_page', 'sulu_io', 'en', 1, true, null, $data[0]->getUuid());
     $this->documentManager->clear();
     $result = $this->mapper->orderAt($site->getUuid(), 3, 17, 'sulu_io', 'en');
     $this->assertEquals($site->getUuid(), $result->getUuid());
     $this->assertEquals('/page-1/test', $result->getPath());
     $this->assertEquals(17, $result->getChanger());
     $this->documentManager->clear();
     $result = $this->documentManager->find($site->getUuid(), 'en');
     $this->assertEquals(30, $result->getSuluOrder());
     $this->assertEquals(RedirectType::INTERNAL, $result->getRedirectType());
     $result = $this->mapper->loadByParent($data[0]->getUuid(), 'sulu_io', 'en');
     $this->assertEquals('/page-1/page-1-1', $result[0]->getPath());
     $this->assertEquals('/page-1/page-1-2', $result[1]->getPath());
     $this->assertEquals('/page-1/test', $result[2]->getPath());
     $this->assertEquals('/page-1/page-1-3', $result[3]->getPath());
     $this->assertEquals('/page-1/page-1-4', $result[4]->getPath());
 }
示例#12
0
 private function loadDocument($pathOrUuid, $locale, $options)
 {
     $document = $this->documentManager->find($pathOrUuid, $locale, array('load_ghost_content' => isset($options['load_ghost_content']) ? $options['load_ghost_content'] : true));
     if ($this->optionsShouldExcludeDocument($document, $options)) {
         return;
     }
     return $document;
 }
示例#13
0
 private function findDocument($uuid, $locale)
 {
     return $this->documentManager->find($uuid, $locale, ['load_ghost_content' => false]);
 }