/** * Edit message event. * * @param TranslationEditMessageEvent $event */ public function addToHistory(TranslationEditMessageEvent $event) { $manager = $this->repository->getManager(); $document = $event->getDocument(); $locale = $this->getLocale($event); $oldMessage = $this->getOldMessage($document, $locale); $historyDocument = $this->setDocument($document, $oldMessage, $locale); $manager->persist($historyDocument); $manager->commit(); }
/** * Tests setter and getter of index name. */ public function testIndexName() { $uniqueIndexName = 'test_index_' . uniqid(); $manager = $this->repository->getManager(); $this->assertNotEquals($uniqueIndexName, $manager->getIndexName()); $manager->setIndexName($uniqueIndexName); $this->assertEquals($uniqueIndexName, $manager->getIndexName()); }
/** * @param array $rawData * @param Repository $repository * @param array $scroll */ public function __construct(array $rawData, Repository $repository, array $scroll = []) { $this->repository = $repository; $this->converter = $repository->getManager()->getConverter(); $this->managerConfig = $repository->getManager()->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']; } }
/** * Converts raw array to document. * * @param array $rawData * @param Repository $repository * * @return DocumentInterface * * @throws \LogicException */ public function convertToDocument($rawData, $repository) { $types = $this->metadataCollector->getMappings($repository->getManager()->getConfig()['mappings']); if (isset($types[$rawData['_type']])) { $metadata = $types[$rawData['_type']]; } else { throw new \LogicException("Got document of unknown type '{$rawData['_type']}'."); } $data = isset($rawData['_source']) ? $rawData['_source'] : array_map('reset', $rawData['fields']); /** @var DocumentInterface $object */ $object = $this->assignArrayToObject($data, new $metadata['namespace'](), $metadata['aliases']); $this->setObjectFields($object, $rawData, ['_id', '_score', 'fields _parent', 'fields _ttl']); return $object; }
/** * Tests cloning documents. */ public function testCloningDocuments() { $manager = $this->repository->getManager(); $document = new ProductDocument(); $document->setId('tuna_id'); $document->title = 'tuna'; $manager->persist($document); $manager->commit(); $document = $this->repository->find('tuna_id'); $clone = clone $document; $this->assertNull($clone->getId(), 'Id should be null\'ed.'); $manager->persist($clone); $manager->commit(); $search = $this->repository->createSearch()->addQuery(new TermQuery('title', 'tuna')); $this->assertCount(2, $this->repository->execute($search), '2 Results should be found.'); }
/** * Converts raw array to document. * * @param array $rawData * @param Repository $repository * * @return DocumentInterface * * @throws \LogicException */ public function convertToDocument($rawData, Repository $repository) { $types = $this->metadataCollector->getMappings($repository->getManager()->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; } /** @var DocumentInterface $object */ $object = $this->assignArrayToObject($rawData, new $metadata['namespace'](), $metadata['aliases']); return $object; }
/** * {@inheritdoc} */ public function commit(Repository $repository) { return $repository->getManager()->commit(); }
/** * Commits document into elasticsearch client. * * @param object $document */ private function commitTranslation($document) { $this->repository->getManager()->persist($document); $this->repository->getManager()->commit(); }