serviceContainer = $serviceContainer; /* @var $this->producer Producer */ $this->producer = $serviceContainer->get('old_sound_rabbit_mq.flowdat_tasklogger_producer'); } /** * @return EntityManagerInterface */ public function getEntityManager() { return $this->serviceContainer->get('doctrine.orm.entity_manager'); } /** * @param Entity $entity * @param string $eventName */ public function execute($entity, $eventName = DoctrineEvents::PRE_PERSIST) { $entityClass = get_class($entity); // la $entity esta dentro de las entidades con workflow if (in_array($entityClass, WorkFlowEntityClasses::getConstants())) { $actionRepository = $this->getEntityManager()->getRepository('WorkflowBundle:Action'); $actions = $actionRepository->findAllByEventAndObjectClass($eventName, $entityClass); foreach ($actions as $action) { $this->publishMessage($action, $entity); } } } /** * @param array $actionName * @param array $entityClass * @param array $entityId */ public function executeAction($actionName, $entityClass, $entityId) { $entityManager = $this->getEntityManager(); $actionRepository = $entityManager->getRepository('WorkflowBundle:Action'); $action = $actionRepository->findOneBy(array( 'name' => $actionName, 'objectClass' => $entityClass, )); $entityRepository = $entityManager->getRepository($entityClass); $entity = $entityRepository->find($entityId); if (in_array($entityClass, WorkFlowEntityClasses::getConstants())) { $this->publishMessage($action, $entity); } } /** * @param Action $action * @param Entity $entity */ public function publishMessage(Action $action, $entity, $routing_key = false) { if($routing_key === false){ $routing_key = ""; if(getenv("AMQP_KEY") !== false){ $routing_key = getenv("AMQP_KEY"); } } $entityClass = get_class($entity); $actionName = $action->getName(); $entityId = $entity->getId(); $msg = array( 'id' => uniqid(), 'content' => $action->render($entity), 'entityClass' => $entityClass, 'entityId' => $entityId, ); $this->producer->publish(serialize($msg), $routing_key); $msg = serialize($msg); $logger = $this->serviceContainer->get('logger'); $logger->info("PUBLISH-RABBIT {$actionName} | {$entityClass}_id_{$entityId} | msg: {$msg}"); } }