public function project($event)
 {
     $userDocument = new User();
     $userDocument->setId("{$event->userId()}");
     $userDocument->setPoints(0);
     $this->manager->persist($userDocument);
     $this->manager->commit();
 }
Esempio n. 2
0
 /**
  * Test if manager builds correct bulk structure
  *
  * @param array  $expected
  * @param array  $calls
  *
  * @dataProvider getTestBulkData()
  */
 public function testBulk($expected, $calls)
 {
     $indices = $this->getMock('Elasticsearch\\Namespaces\\IndicesNamespace', [], [], '', false);
     $esClient = $this->getMock('Elasticsearch\\Client', [], [], '', false);
     $esClient->expects($this->once())->method('bulk')->with($expected);
     $esClient->expects($this->any())->method('indices')->will($this->returnValue($indices));
     $metadataCollector = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\Mapping\\MetadataCollector')->disableOriginalConstructor()->getMock();
     $converter = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\Result\\Converter')->disableOriginalConstructor()->getMock();
     $config = ['readonly' => false];
     $manager = new Manager('test', $config, $esClient, ['index' => 'test'], $metadataCollector, $converter);
     foreach ($calls as list($operation, $type, $query)) {
         $manager->bulk($operation, $type, $query);
     }
     $manager->commit();
 }
 /**
  * Populates elasticsearch with data.
  *
  * @param Manager $manager
  * @param array   $data
  */
 protected function populateElasticsearchWithData($manager, array $data)
 {
     if (!empty($data)) {
         foreach ($data as $type => $documents) {
             foreach ($documents as $document) {
                 $manager->bulk('index', $type, $document);
             }
         }
         $manager->commit();
     }
 }