Modify translations and if conditions in updateReference method

This commit is contained in:
2025-02-26 10:55:43 +01:00
parent 18b86a116f
commit 1eec905a4c
4 changed files with 15 additions and 17 deletions

View File

@@ -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()],
];
}
}
}