Ejemplo n.º 1
0
 /**
  * Exports es index to provided file.
  *
  * @param Manager         $manager
  * @param string          $filename
  * @param array           $types
  * @param int             $chunkSize
  * @param OutputInterface $output
  */
 public function exportIndex(Manager $manager, $filename, $types, $chunkSize, OutputInterface $output)
 {
     $typesMapping = $manager->getMetadataCollector()->getMappings($manager->getConfig()['mappings']);
     $typesToExport = [];
     if ($types) {
         foreach ($types as $type) {
             if (!array_key_exists($type, $typesMapping)) {
                 throw new \InvalidArgumentException(sprintf('Type "%s" does not exist.', $type));
             }
             $typesToExport[] = $typesMapping[$type]['bundle'] . ':' . $typesMapping[$type]['class'];
         }
     } else {
         foreach ($typesMapping as $type => $typeConfig) {
             $typesToExport[] = $typeConfig['bundle'] . ':' . $typeConfig['class'];
         }
     }
     $repo = $manager->getRepository($typesToExport);
     $results = $this->getResults($repo, $chunkSize);
     $progress = new ProgressBar($output, $results->count());
     $progress->setRedrawFrequency(100);
     $progress->start();
     $metadata = ['count' => $results->count(), 'date' => date(\DateTime::ISO8601)];
     $writer = $this->getWriter($this->getFilePath($filename), $metadata);
     foreach ($results as $data) {
         $doc = array_intersect_key($data, array_flip(['_id', '_type', '_source', 'fields']));
         $writer->push($doc);
         $progress->advance();
     }
     $writer->finalize();
     $progress->finish();
     $output->writeln('');
 }
 /**
  * @param array   $rawData
  * @param Manager $manager
  * @param array   $scroll
  */
 public function __construct(array $rawData, Manager $manager, array $scroll = [])
 {
     $this->manager = $manager;
     $this->converter = $manager->getConverter();
     $this->managerConfig = $manager->getConfig();
     if (isset($scroll['_scroll_id']) && isset($scroll['duration'])) {
         $this->scrollId = $scroll['_scroll_id'];
         $this->scrollDuration = $scroll['duration'];
     }
     if (isset($rawData['aggregations'])) {
         $this->aggregations =& $rawData['aggregations'];
     }
     if (isset($rawData['hits']['hits'])) {
         $this->documents = $rawData['hits']['hits'];
     }
     if (isset($rawData['hits']['total'])) {
         $this->count = $rawData['hits']['total'];
     }
 }
Ejemplo n.º 3
0
 /**
  * Converts raw array to document.
  *
  * @param array   $rawData
  * @param Manager $manager
  *
  * @return object
  *
  * @throws \LogicException
  */
 public function convertToDocument($rawData, Manager $manager)
 {
     $types = $this->metadataCollector->getMappings($manager->getConfig()['mappings']);
     if (isset($types[$rawData['_type']])) {
         $metadata = $types[$rawData['_type']];
     } else {
         throw new \LogicException("Got document of unknown type '{$rawData['_type']}'.");
     }
     switch (true) {
         case isset($rawData['_source']):
             $rawData = array_merge($rawData, $rawData['_source']);
             break;
         case isset($rawData['fields']):
             $rawData = array_merge($rawData, $rawData['fields']);
             break;
         default:
             // Do nothing.
             break;
     }
     $object = $this->assignArrayToObject($rawData, new $metadata['namespace'](), $metadata['aliases']);
     return $object;
 }