2015-12-21 125 views
0

为什么我有空的嵌套实体?我有索引人才。在数据库中,人才具有嵌套用户,当现在,当我更新或创建人才时,它不会更新为ElasticSearch中的嵌套对象,我不明白为什么?FOSElasticaBundle更新嵌套实体

fos_elastica: 
clients: 
    default: 
     host: %elastica_host% 
     port: %elastica_port% 
     headers: { Authorization: Basic %elastica_auth_header% } 

indexes: 
    profile: 
     finder: ~ 
     types: 
      talent: 
       mappings: 
        id: 
         type: integer 
        slug: 
         type: string 
        description: 
         type: string 
        user: 
         type: "nested" 
         properties: 
          id: ~ 
          username: 
           type: string 

我搜索和找到替代监听postPersistpostUpdatepreRemove

fos_elastica.listener.talent: 
    class: Artel\SiteBundle\EventListener\ElasticaCourseListener 
    arguments: 
     - @fos_elastica.object_persister.user.user 
     - ['postPersist', 'postUpdate', 'preRemove'] 
     - @fos_elastica.indexable 
    calls: 
     - [ setContainer, ['@service_container', @fos_elastica.object_persister.profile.talent ] ] 
    tags: 
     - { name: 'doctrine.event_subscriber' } 

我自己的听众Artel\SiteBundle\EventListener\ElasticaCourseListener则是这样的:

<?php 

    namespace Artel\SiteBundle\EventListener; 

    use Doctrine\Common\EventArgs; 
    use FOS\ElasticaBundle\Doctrine\Listener as BaseListener; 
    use FOS\ElasticaBundle\Persister\ObjectPersister; 
    use Symfony\Component\DependencyInjection\ContainerInterface; 
    use Artel\ProfileBundle\Entity\Developer; 

    class ElasticaCourseListener extends BaseListener 
    { 
     private $container; 
     private $objectPersisterSession; 

     public function setContainer(ContainerInterface $container, ObjectPersister $objectPersisterSession) 
     { 
      $this->container = $container; 
      $this->objectPersisterSession = $objectPersisterSession; 
     } 

     public function postUpdate(EventArgs $args) 
     { 
      $entity = $args->getEntity(); 

      if ($entity instanceof Developer) { 
       $this->scheduledForUpdate[] = $entity; 
       foreach ($entity->getUser() as $session) { 
        $this->objectPersisterSession->replaceOne($session); 
       } 
      } 
     } 
    } 

现在,我有错误

[Symfony \ Component \ Debug \ Exception \ ContextErrorException]
运行时注意:声明Artel \ SiteBundle \ EventListener \ ElasticaCourseListener :: postUpdate()应该与FOS \ ElasticaBundle \ Doctrine \ Listener :: postUpdate兼容(Doctrine \ Common \持久性\事件\ LifecycleEventArgs $ EventArgs的)

请帮助

回答

0

您必须使用此:

use Doctrine\Common\Persistence\Event\LifecycleEventArgs; 

忘记那一个:

use Doctrine\Common\EventArgs; 

里有一些学说更新;)