@@ 15-43 (lines=29) @@ | ||
12 | /** |
|
13 | * {@inheritdoc} |
|
14 | */ |
|
15 | protected function importExistingEntity( |
|
16 | $entity, |
|
17 | $existingEntity, |
|
18 | $itemData = null, |
|
19 | array $excludedFields = array() |
|
20 | ) { |
|
21 | // manually handle recursive relation to contacts |
|
22 | $entityName = ClassUtils::getClass($entity); |
|
23 | $fieldName = 'contacts'; |
|
24 | ||
25 | if ($entity instanceof Account |
|
26 | && $existingEntity instanceof Account |
|
27 | && !$this->isFieldExcluded($entityName, $fieldName, $itemData) |
|
28 | && !in_array($fieldName, $excludedFields) |
|
29 | ) { |
|
30 | foreach ($existingEntity->getContacts() as $contact) { |
|
31 | $existingEntity->removeContact($contact); |
|
32 | } |
|
33 | ||
34 | foreach ($entity->getContacts() as $contact) { |
|
35 | $contact->removeAccount($entity); |
|
36 | $existingEntity->addContact($contact); |
|
37 | } |
|
38 | ||
39 | $excludedFields[] = $fieldName; |
|
40 | } |
|
41 | ||
42 | parent::importExistingEntity($entity, $existingEntity, $itemData, $excludedFields); |
|
43 | } |
|
44 | } |
|
45 |
@@ 28-60 (lines=33) @@ | ||
25 | /** |
|
26 | * {@inheritdoc} |
|
27 | */ |
|
28 | protected function importExistingEntity( |
|
29 | $entity, |
|
30 | $existingEntity, |
|
31 | $itemData = null, |
|
32 | array $excludedFields = array() |
|
33 | ) { |
|
34 | // manually handle recursive relation to accounts |
|
35 | $entityName = ClassUtils::getClass($entity); |
|
36 | $fieldName = 'accounts'; |
|
37 | ||
38 | if ($entity instanceof Contact |
|
39 | && $existingEntity instanceof Contact |
|
40 | && !$this->isFieldExcluded($entityName, $fieldName, $itemData) |
|
41 | && !in_array($fieldName, $excludedFields) |
|
42 | ) { |
|
43 | foreach ($existingEntity->getAccounts() as $account) { |
|
44 | $existingEntity->removeAccount($account); |
|
45 | } |
|
46 | ||
47 | foreach ($entity->getAccounts() as $account) { |
|
48 | $account->removeContact($entity); |
|
49 | $existingEntity->addAccount($account); |
|
50 | } |
|
51 | ||
52 | $excludedFields[] = $fieldName; |
|
53 | } |
|
54 | ||
55 | parent::importExistingEntity($entity, $existingEntity, $itemData, $excludedFields); |
|
56 | ||
57 | if ($existingEntity instanceof Contact) { |
|
58 | $this->fixDuplicateEntities($existingEntity); |
|
59 | } |
|
60 | } |
|
61 | ||
62 | /** |
|
63 | * {@inheritdoc} |