Remove the transferData method from mergeService

This commit is contained in:
Julie Lenaerts 2025-03-05 19:21:50 +01:00
parent 6ba5c91ee6
commit 09b7558e92

View File

@ -27,7 +27,6 @@ class ThirdpartyMergeService
try { try {
$queries = array_merge( $queries = array_merge(
$this->transferData($toKeep, $toDelete),
$this->updateReferences($toKeep, $toDelete), $this->updateReferences($toKeep, $toDelete),
$this->removeThirdparty($toDelete) $this->removeThirdparty($toDelete)
); );
@ -43,33 +42,6 @@ class ThirdpartyMergeService
} }
} }
/**
* @throws Exception
*/
private function transferData(ThirdParty $toKeep, ThirdParty $toDelete): array
{
$queries = [];
$columns = ['profession', 'firstname', 'name', 'email', 'telephone', 'comment', 'kind', 'contact_data_anonymous', 'types', 'active', 'name_company'];
$metadata = $this->em->getClassMetadata(ThirdParty::class);
foreach ($columns as $column) {
$columnType = $metadata->getTypeOfField($column);
$condition = ('string' === $columnType || 'text' === $columnType)
? "({$column} IS NULL OR {$column} = '')"
: "{$column} IS NULL";
$queries[] = [
'sql' => "
UPDATE chill_3party.third_party
SET {$column} = COALESCE((SELECT {$column} FROM chill_3party.third_party WHERE id = :toDelete), {$column})
WHERE id = :toKeep AND {$condition}",
'params' => ['toDelete' => $toDelete->getId(), 'toKeep' => $toKeep->getId()],
];
}
return $queries;
}
private function updateReferences(ThirdParty $toKeep, ThirdParty $toDelete): array private function updateReferences(ThirdParty $toKeep, ThirdParty $toDelete): array
{ {
$queries = []; $queries = [];