diff --git a/.changes/unreleased/Fixed-20250520-164429.yaml b/.changes/unreleased/Fixed-20250520-164429.yaml new file mode 100644 index 000000000..453094763 --- /dev/null +++ b/.changes/unreleased/Fixed-20250520-164429.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Fix the transfer of evaluations and documents during of accompanyingperiodwork +time: 2025-05-20T16:44:29.093304653+02:00 +custom: + Issue: "" + SchemaChange: No schema change diff --git a/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/AccompanyingPeriodWorkMergeService.php b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/AccompanyingPeriodWorkMergeService.php index ba0f93ce3..490798171 100644 --- a/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/AccompanyingPeriodWorkMergeService.php +++ b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/AccompanyingPeriodWorkMergeService.php @@ -17,9 +17,9 @@ use Doctrine\ORM\EntityManagerInterface; /** * Service for merging two AccompanyingPeriodWork entities into a single entity. */ -class AccompanyingPeriodWorkMergeService +readonly class AccompanyingPeriodWorkMergeService { - public function __construct(private readonly EntityManagerInterface $em) {} + public function __construct(private EntityManagerInterface $em) {} /** * Merges two AccompanyingPeriodWork entities into one by transferring relevant data and removing the obsolete entity. @@ -35,8 +35,9 @@ class AccompanyingPeriodWorkMergeService $this->alterStartDate($toKeep, $toDelete); $this->alterEndDate($toKeep, $toDelete); $this->concatenateComments($toKeep, $toDelete); + $this->transferEvaluationsSQL($toKeep, $toDelete); $this->transferWorkflowsSQL($toKeep, $toDelete); - $this->updateReferencesSQL($toKeep, $toDelete); + $this->updateReferences($toKeep, $toDelete); $entityManager->remove($toDelete); }); @@ -54,6 +55,16 @@ class AccompanyingPeriodWorkMergeService ); } + private function transferEvaluationsSQL(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): void + { + $this->em->getConnection()->executeQuery( + "UPDATE chill_person_accompanying_period_work_evaluation cpapwe + SET accompanyingperiodwork_id = :toKeepId + WHERE cpapwe.accompanyingperiodwork_id = :toDeleteId", + ['toKeepId' => $toKeep->getId(), 'toDeleteId' => $toDelete->getId()] + ); + } + private function alterStartDate(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): void { $startDate = min($toKeep->getStartDate(), $toDelete->getStartDate()); @@ -74,16 +85,17 @@ class AccompanyingPeriodWorkMergeService private function concatenateComments(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): void { - $toKeep->setNote($toKeep->getNote()."\n\n-----------------\n\n".$toDelete->getNote()); - $toKeep->getPrivateComment()->concatenateComments($toDelete->getPrivateComment()); - } - - private function updateReferencesSQL(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): void - { - foreach ($toDelete->getAccompanyingPeriodWorkEvaluations() as $evaluation) { - $toKeep->addAccompanyingPeriodWorkEvaluation($evaluation); + if ($toDelete->getNote() !== '') { + $toKeep->setNote($toKeep->getNote()."\n\n-----------------\n\n".$toDelete->getNote()); } + if (count($toDelete->getPrivateComment()->getComments()) > 0) { + $toKeep->getPrivateComment()->concatenateComments($toDelete->getPrivateComment()); + } + } + + private function updateReferences(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): void + { foreach ($toDelete->getReferrers() as $referrer) { // we only keep the current referrer $toKeep->addReferrer($referrer);