Treat duplicate in backend and setup confirm page of merge

This commit is contained in:
2025-03-05 19:13:17 +01:00
parent 95adc29f9d
commit 6ded185289
9 changed files with 207 additions and 69 deletions

View File

@@ -25,43 +25,13 @@ class AccompanyingPeriodWorkMergeService
*/
public function merge(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): void
{
// Transfer non-duplicate data
$this->transferData($toKeep, $toDelete);
// Update linked entities
$this->updateReferences($toKeep, $toDelete);
$this->em->remove($toDelete);
$this->em->flush();
}
/**
* @throws Exception
*/
private function transferData(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): void
{
$conn = $this->em->getConnection();
$sqlStatements = [
$this->generateStartDateSQL(),
$this->generateEndDateSQL(),
$this->generateCommentSQL(),
];
$conn->beginTransaction();
try {
foreach ($sqlStatements as $sql) {
$conn->executeQuery($sql, ['toDelete' => $toDelete->getId(), 'toKeep' => $toKeep->getId()]);
}
$conn->commit();
} catch (\Exception $e) {
$conn->rollBack();
throw $e;
}
}
private function generateStartDateSQL(): string
/* private function generateStartDateSQL(): string
{
return '
UPDATE chill_person_accompanying_period_work
@@ -99,7 +69,7 @@ class AccompanyingPeriodWorkMergeService
NULLIF(TRIM((SELECT note FROM chill_person_accompanying_period_work WHERE id = :toDelete)), '')
)
WHERE id = :toKeep";
}
}*/
/**
* @throws Exception