Fix merge service and test

This commit is contained in:
2025-04-01 16:15:34 +02:00
parent baa5ba6b7c
commit 18be65a56a
2 changed files with 22 additions and 15 deletions

View File

@@ -60,18 +60,19 @@ class ThirdpartyMergeService
if (($assoc['type'] & ClassMetadata::TO_ONE) !== 0) {
$joinColumn = $meta->getSingleAssociationJoinColumnName($assoc['fieldName']);
if (ThirdParty::class === $assoc['sourceEntity'] && 'parent_id' !== $joinColumn) {
continue;
$suffix = (ThirdParty::class === $assoc['sourceEntity']) ? 'chill_3party.' : '';
if (ThirdParty::class === $assoc['sourceEntity'] && 'parent_id' === $joinColumn) {
$queries[] = [
'sql' => "UPDATE {$suffix}{$tableName} SET parent_id = (SELECT parent_id FROM chill_3party.third_party WHERE id = :toDelete) WHERE id = :toKeep",
'params' => ['toKeep' => $toKeep->getId(), 'toDelete' => $toDelete->getId()],
];
} else {
$queries[] = [
'sql' => "UPDATE {$suffix}{$tableName} SET {$joinColumn} = :toKeep WHERE {$joinColumn} = :toDelete",
'params' => ['toKeep' => $toKeep->getId(), 'toDelete' => $toDelete->getId()],
];
}
$schemaPrefix = (ThirdParty::class === $assoc['sourceEntity'] && 'parent_id' === $joinColumn)
? 'chill_3party.'
: '';
$queries[] = [
'sql' => "UPDATE {$schemaPrefix}{$tableName} SET {$joinColumn} = :toKeep WHERE {$joinColumn} = :toDelete",
'params' => ['toKeep' => $toKeep->getId(), 'toDelete' => $toDelete->getId()],
];
} elseif (8 === $assoc['type'] && isset($assoc['joinTable'])) {
$joinTable = $assoc['joinTable']['name'];
$joinColumn = $assoc['joinTable']['joinColumns'][0]['name'];