mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'testing-202505' of https://gitlab.com/Chill-Projet/chill-bundles into testing-202505
This commit is contained in:
commit
a368e68abb
6
.changes/unreleased/Fixed-20250520-140008.yaml
Normal file
6
.changes/unreleased/Fixed-20250520-140008.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
kind: Fixed
|
||||
body: Fix retrieve schema to form full tablename and construct sql statements correctly in Thirdparty merger.
|
||||
time: 2025-05-20T14:00:08.987229634+02:00
|
||||
custom:
|
||||
Issue: ""
|
||||
SchemaChange: No schema change
|
6
.changes/unreleased/Fixed-20250520-140433.yaml
Normal file
6
.changes/unreleased/Fixed-20250520-140433.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
kind: Fixed
|
||||
body: Fix add missing translation
|
||||
time: 2025-05-20T14:04:33.612140549+02:00
|
||||
custom:
|
||||
Issue: ""
|
||||
SchemaChange: No schema change
|
6
.changes/unreleased/Fixed-20250520-164429.yaml
Normal file
6
.changes/unreleased/Fixed-20250520-164429.yaml
Normal file
@ -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
|
@ -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);
|
||||
|
@ -1509,3 +1509,4 @@ acpw_duplicate:
|
||||
to keep: Action d'accompagnement à conserver
|
||||
to delete: Action d'accompagnement à supprimer
|
||||
Successfully merged: Action d'accompagnement fusionnée avec succès.
|
||||
You cannot merge a accompanying period work with itself. Please choose a different one: Vous ne pouvez pas fusionner un action d'accompagnement avec lui-même. Veuillez en choisir un autre.
|
||||
|
@ -52,32 +52,33 @@ class ThirdpartyMergeService
|
||||
}
|
||||
|
||||
$tableName = $meta->getTableName();
|
||||
$schema = $meta->getSchemaName();
|
||||
$fullTableName = $this->getFullTableName($tableName, $schema);
|
||||
|
||||
foreach ($meta->getAssociationMappings() as $assoc) {
|
||||
if (ThirdParty::class !== $assoc['targetEntity']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// phpstan wants boolean for if condition
|
||||
if (($assoc['type'] & ClassMetadata::TO_ONE) !== 0) {
|
||||
$joinColumn = $meta->getSingleAssociationJoinColumnName($assoc['fieldName']);
|
||||
|
||||
$suffix = (ThirdParty::class === $assoc['sourceEntity']) ? 'chill_3party.' : '';
|
||||
|
||||
$queries[] = [
|
||||
'sql' => "UPDATE {$suffix}{$tableName} SET {$joinColumn} = :toKeep WHERE {$joinColumn} = :toDelete",
|
||||
'sql' => "UPDATE {$fullTableName} SET {$joinColumn} = :toKeep WHERE {$joinColumn} = :toDelete",
|
||||
'params' => ['toKeep' => $toKeep->getId(), 'toDelete' => $toDelete->getId()],
|
||||
];
|
||||
} elseif (ClassMetadata::MANY_TO_MANY === $assoc['type'] && isset($assoc['joinTable'])) {
|
||||
$joinTable = $assoc['joinTable']['name'];
|
||||
$prefix = null !== ($assoc['joinTable']['schema'] ?? null) ? $assoc['joinTable']['schema'].'.' : '';
|
||||
$joinSchema = $assoc['joinTable']['schema'] ?? null;
|
||||
$fullJoinTable = $this->getFullTableName($joinTable, $joinSchema);
|
||||
$joinColumn = $assoc['joinTable']['inverseJoinColumns'][0]['name'];
|
||||
$queries[] = [
|
||||
'sql' => "UPDATE {$prefix}{$joinTable} SET {$joinColumn} = :toKeep WHERE {$joinColumn} = :toDelete AND NOT EXISTS (SELECT 1 FROM {$prefix}{$joinTable} WHERE {$joinColumn} = :toKeep)",
|
||||
'sql' => "UPDATE {$fullJoinTable} SET {$joinColumn} = :toKeep WHERE {$joinColumn} = :toDelete AND NOT EXISTS (SELECT 1 FROM {$fullJoinTable} WHERE {$joinColumn} = :toKeep)",
|
||||
'params' => ['toDelete' => $toDelete->getId(), 'toKeep' => $toKeep->getId()],
|
||||
];
|
||||
|
||||
$queries[] = [
|
||||
'sql' => "DELETE FROM {$joinTable} WHERE {$joinColumn} = :toDelete",
|
||||
'sql' => "DELETE FROM {$fullJoinTable} WHERE {$joinColumn} = :toDelete",
|
||||
'params' => ['toDelete' => $toDelete->getId()],
|
||||
];
|
||||
}
|
||||
@ -104,4 +105,27 @@ class ThirdpartyMergeService
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Helper method to retrieve full table name of the different associations
|
||||
// (e.g. "chill_3party.third_party" or "public.chill_3party.third_party")
|
||||
//
|
||||
// If the table name is already schema-qualified, it is returned as-is.
|
||||
//
|
||||
// If the table name is not schema-qualified, it is prefixed with the
|
||||
// schema name of the target entity (e.g. "public.chill_3party.third_party").
|
||||
//
|
||||
// If the table name is not schema-qualified and the target entity has no
|
||||
// schema name, the table name is prefixed with "public".
|
||||
private function getFullTableName(string $tableName, ?string $schema): string
|
||||
{
|
||||
if ($schema !== null) {
|
||||
return "{$schema}.{$tableName}";
|
||||
}
|
||||
|
||||
if (str_contains($tableName, '.')) {
|
||||
return $tableName;
|
||||
}
|
||||
|
||||
return "public.{$tableName}";
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user