Пример #1
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));
     }
 }
Пример #2
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));
     }
 }
Пример #3
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());
 }
Пример #4
0
 /**
  * Returns node path from given uuid.
  *
  * @param $uuids
  *
  * @return string[]
  */
 protected function getPathsByUuids($uuids)
 {
     $paths = [];
     $where = [];
     foreach ($uuids as $uuid) {
         $where[] = sprintf('[jcr:uuid] = "%s"', $uuid);
     }
     $queryString = 'SELECT * FROM [nt:unstructured] AS a WHERE ' . implode(' OR ', $where);
     $query = $this->documentManager->createQuery($queryString);
     $result = $query->execute();
     /** @var BasePageDocument $page */
     foreach ($result as $page) {
         $paths[$page->getUuid()] = $page->getPath();
     }
     return $paths;
 }
Пример #5
0
 /**
  * {@inheritDoc}
  */
 public function loadByQuery(QueryInterface $query, $locale, $webspaceKey = null, $excludeGhost = true, $loadGhostContent = false)
 {
     $options = array('exclude_ghost' => $excludeGhost, 'load_ghost_content' => $loadGhostContent);
     $documents = $this->documentManager->createQuery($query, $locale, $options)->execute();
     return $this->documentsToStructureCollection($documents, $options);
 }
Пример #6
0
 /**
  * Return snippets.
  *
  * If $type is given then only return the snippets of that type.
  *
  * @param string $locale
  * @param string $type         Optional snippet type
  * @param int    $offset       Optional offset
  * @param int    $max          Optional max
  * @param string $search
  * @param string $sortBy
  * @param string $sortOrder
  *
  * @throws \InvalidArgumentException
  *
  * @return SnippetBridge[]
  */
 public function getSnippets($locale, $type = null, $offset = null, $max = null, $search = null, $sortBy = null, $sortOrder = null)
 {
     $query = $this->getSnippetsQuery($locale, $type, $offset, $max, $search, $sortBy, $sortOrder);
     $documents = $this->documentManager->createQuery($query, $locale, ['load_ghost_content' => true])->execute();
     return $documents;
 }