Ejemplo n.º 1
0
 public function testRemoveActivityTargetForNullTarget()
 {
     $activityEntity = $this->getMock('Oro\\Bundle\\ActivityBundle\\Model\\ActivityInterface');
     $activityEntity->expects($this->never())->method('supportActivityTarget');
     $activityEntity->expects($this->never())->method('hasActivityTarget');
     $activityEntity->expects($this->never())->method('removeActivityTarget');
     $this->assertFalse($this->manager->removeActivityTarget($activityEntity, null));
 }
 /**
  * Handle delete entity object.
  *
  * @param RelationIdentifier $id
  * @param ApiEntityManager   $manager
  *
  * @throws EntityNotFoundException if an entity with the given id does not exist
  * @throws ForbiddenException if a delete operation is forbidden
  */
 public function handleDelete($id, ApiEntityManager $manager)
 {
     $em = $manager->getObjectManager();
     /** @var ActivityInterface $entity */
     $entity = $em->find($id->getOwnerEntityClass(), $id->getOwnerEntityId());
     if (!$entity) {
         throw new EntityNotFoundException();
     }
     $this->checkPermissions($entity, $em);
     $targetEntity = $em->find($id->getTargetEntityClass(), $id->getTargetEntityId());
     if (!$targetEntity) {
         throw new EntityNotFoundException();
     }
     $this->checkPermissionsForTargetEntity($targetEntity, $em);
     $this->activityManager->removeActivityTarget($entity, $targetEntity);
     $em->flush();
 }
 /**
  * Handle delete entity object.
  *
  * @param RelationIdentifier $id
  * @param ApiEntityManager   $manager
  *
  * @throws EntityNotFoundException if an entity with the given id does not exist
  * @throws ForbiddenException if a delete operation is forbidden
  */
 public function handleDelete($id, ApiEntityManager $manager)
 {
     $em = $manager->getObjectManager();
     /** @var ActivityInterface $entity */
     $entity = $em->find($id->getOwnerEntityClass(), $id->getOwnerEntityId());
     if (!$entity) {
         throw new EntityNotFoundException();
     }
     if (!$this->securityFacade->isGranted('EDIT', $entity)) {
         throw new ForbiddenException('has no edit permissions for activity entity');
     }
     $targetEntity = $em->find($id->getTargetEntityClass(), $id->getTargetEntityId());
     if (!$targetEntity) {
         throw new EntityNotFoundException();
     }
     if (!$this->securityFacade->isGranted('VIEW', $targetEntity)) {
         throw new ForbiddenException('has no view permissions for related entity');
     }
     $this->activityManager->removeActivityTarget($entity, $targetEntity);
     $em->flush();
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $sourceEntity = $fieldData->getSourceEntity();
     if ($masterEntity->getId() !== $sourceEntity->getId()) {
         $fieldMetadata = $fieldData->getMetadata();
         $activityClass = $fieldMetadata->get('type');
         $activityListItems = $this->getActivitiesByEntity($masterEntity, $activityClass);
         $activityIds = ArrayUtil::arrayColumn($activityListItems, 'relatedActivityId');
         $activities = $this->doctrineHelper->getEntityRepository($activityClass)->findBy(['id' => $activityIds]);
         foreach ($activities as $activity) {
             $this->activityManager->removeActivityTarget($activity, $masterEntity);
         }
         $activityListItems = $this->getActivitiesByEntity($sourceEntity, $activityClass);
         $activityIds = ArrayUtil::arrayColumn($activityListItems, 'id');
         $entityClass = ClassUtils::getRealClass($masterEntity);
         $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
         $activityIds = ArrayUtil::arrayColumn($activityListItems, 'relatedActivityId');
         $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId(), $activityClass);
     }
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function removeActivityTarget(ActivityInterface $activityEntity, $targetEntity)
 {
     return $this->activityManager->removeActivityTarget($activityEntity, $targetEntity);
 }