|
@@ -5,24 +5,25 @@ namespace WorkflowBundle\EventListener;
|
|
use Doctrine\Common\EventSubscriber;
|
|
use Doctrine\Common\EventSubscriber;
|
|
use Doctrine\ORM\Event\LifecycleEventArgs;
|
|
use Doctrine\ORM\Event\LifecycleEventArgs;
|
|
use WorkflowBundle\Utils\DoctrineEvents;
|
|
use WorkflowBundle\Utils\DoctrineEvents;
|
|
-use WorkflowBundle\Utils\WorkFlowEntityClasses;
|
|
|
|
-use OldSound\RabbitMqBundle\RabbitMq\Producer;
|
|
|
|
|
|
+use WorkflowBundle\Services\ProducerService;
|
|
|
|
+use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
|
|
class DoctrineEventSubscriber implements EventSubscriber
|
|
class DoctrineEventSubscriber implements EventSubscriber
|
|
{
|
|
{
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @var Producer
|
|
|
|
|
|
+ * @var ProducerService
|
|
*/
|
|
*/
|
|
- private $producer;
|
|
|
|
|
|
+ private $producerService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Producer $producer
|
|
|
|
|
|
+ * @param ContainerInterface $serviceContainer
|
|
*/
|
|
*/
|
|
- public function __construct(Producer $producer)
|
|
|
|
|
|
+ public function __construct(ContainerInterface $serviceContainer)
|
|
{
|
|
{
|
|
- $this->producer = $producer;
|
|
|
|
|
|
+ /* @var $this->producerService ProducerService */
|
|
|
|
+ $this->producerService = $serviceContainer->get('workflow.producer_service');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -30,7 +31,14 @@ class DoctrineEventSubscriber implements EventSubscriber
|
|
*/
|
|
*/
|
|
public function getSubscribedEvents()
|
|
public function getSubscribedEvents()
|
|
{
|
|
{
|
|
- return DoctrineEvents::getConstants();
|
|
|
|
|
|
+ return array(
|
|
|
|
+ DoctrineEvents::PRE_PERSIST,
|
|
|
|
+ DoctrineEvents::POST_PERSIST,
|
|
|
|
+ DoctrineEvents::PRE_UPDATE,
|
|
|
|
+ DoctrineEvents::POST_UPDATE,
|
|
|
|
+ DoctrineEvents::PRE_REMOVE,
|
|
|
|
+ DoctrineEvents::POST_REMOVE,
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -87,25 +95,7 @@ class DoctrineEventSubscriber implements EventSubscriber
|
|
*/
|
|
*/
|
|
public function execute(LifecycleEventArgs $args, $eventName = DoctrineEvents::PRE_PERSIST)
|
|
public function execute(LifecycleEventArgs $args, $eventName = DoctrineEvents::PRE_PERSIST)
|
|
{
|
|
{
|
|
- $entity = $args->getEntity();
|
|
|
|
- $entityManager = $args->getEntityManager();
|
|
|
|
- $entityClass = get_class($entity);
|
|
|
|
-
|
|
|
|
- // la $entity esta dentro de las entidades con workflow
|
|
|
|
- if (in_array($entityClass, WorkFlowEntityClasses::getConstants())) {
|
|
|
|
- $doctrine2WorkFlowActionRepository = $entityManager->getRepository('WorkflowBundle:Doctrine2WorkFlowAction');
|
|
|
|
- $doctrine2WorkFlowActions = $doctrine2WorkFlowActionRepository->findAllByEventAndEntityClass($eventName, $entityClass);
|
|
|
|
- foreach ($doctrine2WorkFlowActions as $doctrine2WorkFlowAction) {
|
|
|
|
- $actions = $doctrine2WorkFlowAction->getActions();
|
|
|
|
- foreach ($actions as $action) {
|
|
|
|
- $msg = array(
|
|
|
|
- 'id' => uniqid(),
|
|
|
|
- 'cmd' => $action->getCmd($entity),
|
|
|
|
- );
|
|
|
|
- $this->producer->publish(serialize($msg));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ $this->producerService->execute($args->getEntity(), $eventName);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|