diff --git a/src/Bundle/ChillMainBundle/Resources/views/CRUD/_view_content.html.twig b/src/Bundle/ChillMainBundle/Resources/views/CRUD/_view_content.html.twig
index 7d0023a39..4102f8a21 100644
--- a/src/Bundle/ChillMainBundle/Resources/views/CRUD/_view_content.html.twig
+++ b/src/Bundle/ChillMainBundle/Resources/views/CRUD/_view_content.html.twig
@@ -48,8 +48,8 @@
{{ 'thirdparty_duplicate.merge'|trans }}
+ title="{{ 'Merge'|trans }}"
+ class="btn btn-misc">{{ 'Merge'|trans }}
{% endblock %}
{% block content_view_actions_edit_link %}
diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/find_duplicate.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/find_duplicate.html.twig
index aea022791..53f7ddc5d 100644
--- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/find_duplicate.html.twig
+++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/find_duplicate.html.twig
@@ -8,7 +8,7 @@
{% block content %}
-
{{ 'find duplicate thirdparty'|trans }}
+ {{ 'find_thirdparty_duplicate'|trans }}
{{ form_start(form) }}
{{ form_rest(form) }}
diff --git a/src/Bundle/ChillThirdPartyBundle/Service/ThirdpartyMergeService.php b/src/Bundle/ChillThirdPartyBundle/Service/ThirdpartyMergeService.php
index 250144efd..0c1d88e52 100644
--- a/src/Bundle/ChillThirdPartyBundle/Service/ThirdpartyMergeService.php
+++ b/src/Bundle/ChillThirdPartyBundle/Service/ThirdpartyMergeService.php
@@ -86,7 +86,7 @@ class ThirdpartyMergeService
continue;
}
- if (ClassMetadata::TO_ONE === $assoc['type']) {
+ if ($assoc['type'] & ClassMetadata::TO_ONE) {
$joinColumn = $meta->getSingleAssociationJoinColumnName($assoc['fieldName']);
if (ThirdParty::class === $assoc['sourceEntity'] && 'parent_id' !== $joinColumn) {
@@ -104,21 +104,18 @@ class ThirdpartyMergeService
];
}
- if (ClassMetadata::TO_MANY === $assoc['type'] && isset($assoc['joinTable'])) {
-
+ if ($assoc['type'] === 8 && isset($assoc['joinTable'])) {
$joinTable = $assoc['joinTable']['name'];
$joinColumn = $assoc['joinTable']['joinColumns'][0]['name'];
- if ('thirdparty_id' === $joinColumn) {
- $queries[] = [
- 'sql' => "DELETE FROM {$joinTable} WHERE {$joinColumn} = :toDelete",
- 'params' => ['toDelete' => $toDelete->getId()],
- ];
- } else {
- $queries[] = [
- 'sql' => "UPDATE {$joinTable} SET {$joinColumn} = :toKeep WHERE {$joinColumn} = :toDelete",
- 'params' => ['toKeep' => $toKeep->getId(), 'toDelete' => $toDelete->getId()],
- ];
- }
+ $queries[] = [
+ 'sql' => "UPDATE {$joinTable} SET {$joinColumn} = :toKeep WHERE {$joinColumn} = :toDelete AND NOT EXISTS (SELECT 1 FROM {$joinTable} WHERE {$joinColumn} = :toKeep)",
+ 'params' => ['toDelete' => $toDelete->getId(), 'toKeep' => $toKeep->getId()],
+ ];
+
+ $queries[] = [
+ 'sql' => "DELETE FROM {$joinTable} WHERE {$joinColumn} = :toDelete",
+ 'params' => ['toDelete' => $toDelete->getId()],
+ ];
}
}
}
diff --git a/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml b/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml
index 0aa3bfda9..908e045e3 100644
--- a/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml
+++ b/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml
@@ -133,6 +133,4 @@ is thirdparty: Le demandeur est un tiers
Filter by person's who have a residential address located at a thirdparty of type: Filtrer les usagers qui ont une addresse de résidence chez un tiers
"Filtered by person's who have a residential address located at a thirdparty of type %thirdparty_type% and valid on %date_calc%": "Uniquement les usagers qui ont une addresse de résidence chez un tiers de catégorie %thirdparty_type% et valide sur la date %date_calc%"
-thirdparty_duplicate:
- merge: Fussioner
- find: 'Désigner un tiers doublon'
+find_thirdparty_duplicate: 'Désigner un tiers doublon'