Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $sourceEntity = $fieldData->getSourceEntity();
     if ($masterEntity->getId() !== $sourceEntity->getId()) {
         $queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $masterEntity->getId());
         $notes = $queryBuilder->getQuery()->getResult();
         if (!empty($notes)) {
             $entityManager = $this->doctrineHelper->getEntityManager(current($notes));
             foreach ($notes as $note) {
                 $entityManager->remove($note);
             }
         }
         $queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $sourceEntity->getId());
         $notes = $queryBuilder->getQuery()->getResult();
         if (!empty($notes)) {
             foreach ($notes as $note) {
                 $note->setTarget($masterEntity);
             }
         }
         $fieldMetadata = $fieldData->getMetadata();
         $activityClass = $fieldMetadata->get('type');
         $entityClass = ClassUtils::getRealClass($sourceEntity);
         $queryBuilder = $this->doctrineHelper->getEntityRepository(ActivityList::ENTITY_NAME)->getActivityListQueryBuilderByActivityClass($entityClass, $sourceEntity->getId(), $activityClass);
         $activityListItems = $queryBuilder->getQuery()->getResult();
         $activityIds = ArrayUtils::arrayColumn($activityListItems, 'id');
         $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
     }
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $fieldMetadata = $fieldData->getMetadata();
     $entities = $fieldData->getEntityData()->getEntities();
     foreach ($entities as $sourceEntity) {
         if ($sourceEntity->getId() !== $masterEntity->getId()) {
             $entityClass = ClassUtils::getRealClass($masterEntity);
             $activityClass = $fieldMetadata->get('type');
             $queryBuilder = $this->doctrineHelper->getEntityRepository(ActivityList::ENTITY_NAME)->getActivityListQueryBuilderByActivityClass($entityClass, $sourceEntity->getId(), $activityClass);
             $activityListItems = $queryBuilder->getQuery()->getResult();
             $activityIds = ArrayUtils::arrayColumn($activityListItems, 'id');
             $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
             $activityIds = ArrayUtils::arrayColumn($activityListItems, 'relatedActivityId');
             $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId(), $activityClass);
         }
     }
 }
Esempio n. 3
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);
     }
 }