Revert "FIX [duplicates] reinstate gestion des doublons"

This reverts commit 5351223d44.
This commit is contained in:
2023-05-24 13:09:04 +02:00
parent 8b82e0c535
commit 5109490aad
5 changed files with 35 additions and 75 deletions

View File

@@ -13,11 +13,7 @@ namespace Chill\PersonBundle\Actions\Remove;
use Chill\PersonBundle\Actions\ActionEvent;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Relationships\Relationship;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -46,10 +42,9 @@ class PersonMove
protected $eventDispatcher;
public function __construct(
EntityManagerInterface $em,
EntityManagerInterface $em,
EventDispatcherInterface $eventDispatcher
)
{
) {
$this->em = $em;
$this->eventDispatcher = $eventDispatcher;
}
@@ -89,11 +84,8 @@ class PersonMove
}
foreach ($metadata->getAssociationMappings() as $field => $mapping) {
if (in_array($mapping['sourceEntity'], $this->getIgnoredEntities())) {
continue;
}
if (Person::class === $mapping['targetEntity'] and true === $mapping['isOwningSide']) {
if (in_array($mapping['sourceEntity'], $toDelete, true)) {
if (Person::class === $mapping['targetEntity']) {
if (in_array($metadata->getName(), $toDelete, true)) {
$sql = $this->createDeleteSQL($metadata, $from, $field);
$event = new ActionEvent(
$from->getId(),
@@ -125,11 +117,10 @@ class PersonMove
$from->getId()
);
dump($sqls);
return $sqls;
}
private function createDeleteSQL(ClassMetadata $metadata, Person $from, $field): string
protected function createDeleteSQL(ClassMetadata $metadata, Person $from, $field): string
{
$mapping = $metadata->getAssociationMapping($field);
@@ -146,41 +137,26 @@ class PersonMove
);
}
private function createMoveSQL(ClassMetadata $metadata, Person $from, Person $to, $field): string
protected function createMoveSQL(ClassMetadata $metadata, Person $from, Person $to, $field): string
{
$mapping = $metadata->getAssociationMapping($field);
// Set part of the query, aka <here> in "UPDATE table SET <here> "
$sets = [];
foreach ($mapping['joinColumns'] as $columns) {
$sets[] = sprintf('%s = %d', $columns['name'], $to->getId());
}
$conditions = [];
dump($mapping);
if (array_key_exists('joinTable', $mapping)) {
$tableName = (null !== ($mapping['joinTable']['schema'] ?? null) ? $mapping['joinTable']['schema'] . '.' : '')
. $mapping['joinTable']['name'];
foreach ($mapping['joinTable']['inverseJoinColumns'] as $columns) {
$sets[] = sprintf('%s = %d', $columns['name'], $to->getId());
}
foreach ($mapping['joinTable']['inverseJoinColumns'] as $columns) {
$conditions[] = sprintf('%s = %d', $columns['name'], $from->getId());
}
} elseif (array_key_exists('joinColumns', $mapping)) {
$tableName = $this->getTableName($metadata);
foreach ($mapping['joinColumns'] as $columns) {
$sets[] = sprintf('%s = %d', $columns['name'], $to->getId());
}
foreach ($mapping['joinColumns'] as $columns) {
$conditions[] = sprintf('%s = %d', $columns['name'], $from->getId());
}
foreach ($mapping['joinColumns'] as $columns) {
$conditions[] = sprintf('%s = %d', $columns['name'], $from->getId());
}
return sprintf(
'UPDATE %s SET %s WHERE %s',
$tableName,
$this->getTableName($metadata),
implode(' ', $sets),
implode(' AND ', $conditions)
);
@@ -190,23 +166,10 @@ class PersonMove
* return an array of classes where entities should be deleted
* instead of moved.
*/
private function getDeleteEntities(): array
protected function getDeleteEntities(): array
{
return [
Person\PersonCenterHistory::class,
HouseholdMember::class,
AccompanyingPeriodParticipation::class,
AccompanyingPeriod\AccompanyingPeriodWork::class,
Relationship::class
];
}
private function getIgnoredEntities(): array
{
return [
Person\PersonCurrentAddress::class,
PersonHouseholdAddress::class,
Person\PersonCenterCurrent::class,
AccompanyingPeriod::class,
];
}