mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix handling comments and workflows on acpw
This commit is contained in:
parent
f523b9adb3
commit
5e6833975b
@ -31,13 +31,16 @@ class AccompanyingPeriodWorkMergeService
|
||||
|
||||
try {
|
||||
$queries = array_merge(
|
||||
$this->updateReferences($toKeep, $toDelete),
|
||||
$this->updateReferencesSQL($toKeep, $toDelete),
|
||||
$this->transferWorkflowsSQL($toKeep, $toDelete),
|
||||
$this->generateStartDateSQL($toDelete, $toKeep),
|
||||
$this->generateEndDateSQL($toDelete, $toKeep),
|
||||
$this->generateCommentSQL($toDelete, $toKeep),
|
||||
$this->removeAccompanyingPeriodWork($toDelete)
|
||||
);
|
||||
|
||||
foreach ($queries as $query) {
|
||||
dump($query);
|
||||
$conn->executeStatement($query['sql'], $query['params']);
|
||||
}
|
||||
|
||||
@ -49,6 +52,20 @@ class AccompanyingPeriodWorkMergeService
|
||||
}
|
||||
}
|
||||
|
||||
private function transferWorkflowsSQL(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): array
|
||||
{
|
||||
$queries = [];
|
||||
$queries[] = [
|
||||
'sql' => "UPDATE chill_main_workflow_entity w
|
||||
SET relatedentityid = :toKeepId
|
||||
WHERE w.relatedentityid = :toDeleteId
|
||||
AND w.relatedentityclass = 'Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork'",
|
||||
'params' => ['toKeepId' => $toKeep->getId(), 'toDeleteId' => $toDelete->getId()],
|
||||
];
|
||||
|
||||
return $queries;
|
||||
}
|
||||
|
||||
private function generateStartDateSQL(AccompanyingPeriodWork $toDelete, AccompanyingPeriodWork $toKeep): array
|
||||
{
|
||||
$queries = [];
|
||||
@ -89,7 +106,41 @@ class AccompanyingPeriodWorkMergeService
|
||||
return $queries;
|
||||
}
|
||||
|
||||
private function updateReferences(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): array
|
||||
private function generateCommentSQL(AccompanyingPeriodWork $toDelete, AccompanyingPeriodWork $toKeep): array
|
||||
{
|
||||
$queries = [];
|
||||
$queries[] = [
|
||||
'sql' => "WITH updated_values AS (
|
||||
SELECT
|
||||
acpw1.id AS to_update,
|
||||
acpw1.note || ' ' || acpw2.note AS new_note,
|
||||
jsonb_set(
|
||||
acpw1.privatecomment_comments::jsonb,
|
||||
'{1}',
|
||||
to_jsonb((acpw1.privatecomment_comments::jsonb->>'1') || ' ' || (acpw2.privatecomment_comments::jsonb->>'1'))
|
||||
) AS new_privatecomment_comments
|
||||
FROM
|
||||
chill_person_accompanying_period_work acpw1,
|
||||
chill_person_accompanying_period_work acpw2
|
||||
WHERE
|
||||
acpw1.id = :toKeep AND
|
||||
acpw2.id = :toDelete
|
||||
)
|
||||
UPDATE chill_person_accompanying_period_work
|
||||
SET
|
||||
note = updated_values.new_note,
|
||||
privatecomment_comments = updated_values.new_privatecomment_comments
|
||||
FROM
|
||||
updated_values
|
||||
WHERE
|
||||
chill_person_accompanying_period_work.id = updated_values.to_update",
|
||||
'params' => ['toDelete' => $toDelete->getId(), 'toKeep' => $toKeep->getId()],
|
||||
];
|
||||
|
||||
return $queries;
|
||||
}
|
||||
|
||||
private function updateReferencesSQL(AccompanyingPeriodWork $toKeep, AccompanyingPeriodWork $toDelete): array
|
||||
{
|
||||
$queries = [];
|
||||
$allMeta = $this->em->getMetadataFactory()->getAllMetadata();
|
||||
|
Loading…
x
Reference in New Issue
Block a user