예제 #1
0
 /**
  * Update the elastica index when a new message is sent
  *
  * @param NewMessageEvent $event The event
  */
 public function onNew(NewMessageEvent $event)
 {
     if ($event->isFirst()) {
         // A new discussion was created, add it to the elasticsearch index
         $this->groupPersister->insertOne($event->getMessage()->getGroup());
     }
     $this->messagePersister->insertOne($event->getMessage());
 }
예제 #2
0
 /**
  * Persist scheduled objects to ElasticSearch
  * After persisting, clear the scheduled queue to prevent multiple data updates when using multiple flush calls
  */
 private function persistScheduled()
 {
     /*if (count($this->scheduledForInsertion)) {
           $this->objectPersister->insertMany($this->scheduledForInsertion);
           $this->scheduledForInsertion = array();
       }
       if (count($this->scheduledForUpdate)) {
           $this->objectPersister->replaceMany($this->scheduledForUpdate);
           $this->scheduledForUpdate = array();
       }
       if (count($this->scheduledForDeletion)) {
           $this->objectPersister->deleteManyByIdentifiers($this->scheduledForDeletion);
           $this->scheduledForDeletion = array();
       }*/
     if ($this->shouldPersist()) {
         if (count($this->scheduledForInsertion)) {
             $this->objectPersister->insertMany($this->scheduledForInsertion);
             $this->scheduledForInsertion = array();
         }
         if (count($this->scheduledForUpdate)) {
             $this->objectPersister->replaceMany($this->scheduledForUpdate);
             $this->scheduledForUpdate = array();
         }
         if (count($this->scheduledForDeletion)) {
             $this->objectPersister->deleteManyByIdentifiers($this->scheduledForDeletion);
             $this->scheduledForDeletion = array();
         }
     }
 }
 /**
  * Removes the object if it was scheduled for removal.
  *
  * This is usually called during the post-remove event.
  *
  * @param object $object
  */
 protected function removeIfScheduled($object)
 {
     $objectHash = spl_object_hash($object);
     if (isset($this->scheduledForRemoval[$objectHash])) {
         $this->objectPersister->deleteById($this->scheduledForRemoval[$objectHash]);
         unset($this->scheduledForRemoval[$objectHash]);
     }
 }
 public function testThatCanInsertManyObjects()
 {
     $transformer = $this->getTransformer();
     /** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica\Type */
     $typeMock = $this->getMockBuilder('Elastica\\Type')->disableOriginalConstructor()->getMock();
     $typeMock->expects($this->never())->method('deleteById');
     $typeMock->expects($this->never())->method('addDocument');
     $typeMock->expects($this->once())->method('addDocuments');
     $fields = array('name' => array());
     $objectPersister = new ObjectPersister($typeMock, $transformer, 'SomeClass', $fields);
     $objectPersister->insertMany(array(new POPO(), new POPO()));
 }
예제 #5
0
 /**
  * @param ProductInterface $product
  */
 private function addScheduledForUpdate(ProductInterface $product)
 {
     if ($this->objectPersister->handlesObject($product)) {
         $this->scheduledForUpdate[] = $product;
     }
 }
 public function __construct(Type $type, ModelToElasticaTransformerInterface $transformer, $objectClass, $serializer)
 {
     parent::__construct($type, $transformer, $objectClass, array());
     $this->serializer = $serializer;
 }