Open macnibblet opened 9 years ago
Since docrine added entity listeners the synchronizer is no longer required. So what you have to do is register a entity listener, inject the document service and then just listen to update/delete/persist events
use Company\Entity\CompanyEntity;
use Doctrine\ORM\Event\LifecycleEventArgs;
use MCNElasticSearch\Service\DocumentService;
/**
* Class CompanyEntityListener
*
* Listens for changes to the entity and updates elastic search with them
*/
class CompanyEntityListener
{
/**
* @var \MCNElasticSearch\Service\DocumentService
*/
private $documentService;
/**
* @param DocumentService $documentService
*/
public function __construct(DocumentService $documentService)
{
$this->documentService = $documentService;
}
public function remove(CompanyEntity $company, LifecycleEventArgs $event)
{
$this->documentService->delete($company);
}
public function update(CompanyEntity $company, LifecycleEventArgs $event)
{
$this->documentService->update($company);
}
public function persist(CompanyEntity $company, LifecycleEventArgs $event)
{
$this->documentService->add($company);
}
}
Ok, i've created the EntityListener, and used it through the annotation @ORM\EntityListeners({"CompanyEntityListener"}), but i don't know how to instantiate the $documentService. :(
If i am right, the Elastica was removed, and the Synchroniser from the step two of the Readme no longer exists. Now i am lost, do you have some working code i can use as example?