mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Remove the transferData method from mergeService
This commit is contained in:
parent
6ba5c91ee6
commit
09b7558e92
@ -27,7 +27,6 @@ class ThirdpartyMergeService
|
||||
|
||||
try {
|
||||
$queries = array_merge(
|
||||
$this->transferData($toKeep, $toDelete),
|
||||
$this->updateReferences($toKeep, $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
|
||||
{
|
||||
$queries = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user