Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function onSuccess($entity)
 {
     /** @var ActivityInterface $activity */
     $activity = $entity['activity'];
     /** @var ArrayCollection $relations */
     $relations = $entity['relations'];
     $this->activityManager->addActivityTargets($activity, $relations->toArray());
     $this->entityManager->flush();
 }
Ejemplo n.º 2
0
 public function testAddActivityTargetsForNotSupportedTarget()
 {
     $activityEntity = $this->getMock('Oro\\Bundle\\ActivityBundle\\Model\\ActivityInterface');
     $targetEntity = new Target();
     $activityEntity->expects($this->once())->method('supportActivityTarget')->with(get_class($targetEntity))->will($this->returnValue(false));
     $activityEntity->expects($this->never())->method('hasActivityTarget')->with($this->identicalTo($targetEntity));
     $activityEntity->expects($this->never())->method('addActivityTarget')->with($this->identicalTo($targetEntity));
     $this->assertFalse($this->manager->addActivityTargets($activityEntity, [$targetEntity]));
 }
Ejemplo n.º 3
0
 /**
  * Handle onFlush event
  *
  * @param OnFlushEventArgs $event
  */
 public function handleOnFlush(OnFlushEventArgs $event)
 {
     $em = $event->getEntityManager();
     $uow = $em->getUnitOfWork();
     $newEntities = $uow->getScheduledEntityInsertions();
     foreach ($newEntities as $entity) {
         if ($entity instanceof Email) {
             // prepare the list of association targets
             $targets = [];
             $this->addSenderOwner($targets, $entity);
             $this->addRecipientOwners($targets, $entity);
             // add associations
             $hasChanges = $this->activityManager->addActivityTargets($entity, $targets);
             // recompute change set if needed
             if ($hasChanges) {
                 $uow->computeChangeSet($em->getClassMetadata(ClassUtils::getClass($entity)), $entity);
             }
         }
     }
 }