38 lines
1,004 B
PHP
38 lines
1,004 B
PHP
<?php
|
|
|
|
namespace FOQ\ElasticaBundle\Doctrine\MongoDB;
|
|
|
|
use FOQ\ElasticaBundle\Doctrine\AbstractListener;
|
|
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;
|
|
use Doctrine\Common\EventSubscriber;
|
|
|
|
class Listener extends AbstractListener implements EventSubscriber
|
|
{
|
|
public function postPersist(LifecycleEventArgs $eventArgs)
|
|
{
|
|
$document = $eventArgs->getDocument();
|
|
|
|
if ($document instanceof $this->objectClass) {
|
|
$this->objectPersister->insertOne($document);
|
|
}
|
|
}
|
|
|
|
public function postUpdate(LifecycleEventArgs $eventArgs)
|
|
{
|
|
$document = $eventArgs->getDocument();
|
|
|
|
if ($document instanceof $this->objectClass) {
|
|
$this->objectPersister->replaceOne($document);
|
|
}
|
|
}
|
|
|
|
public function postRemove(LifecycleEventArgs $eventArgs)
|
|
{
|
|
$document = $eventArgs->getDocument();
|
|
|
|
if ($document instanceof $this->objectClass) {
|
|
$this->objectPersister->deleteOne($document);
|
|
}
|
|
}
|
|
}
|