Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Historique suppression UserPartner #3608

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/EventListener/EntityHistoryListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#[AsDoctrineListener(event: Events::postPersist)]
#[AsDoctrineListener(event: Events::postUpdate)]
#[AsDoctrineListener(event: Events::preRemove)]
readonly class EntityHistoryListener
class EntityHistoryListener
{
public const array FIELDS_TO_IGNORE = [
'lastLoginAt',
Expand All @@ -27,13 +27,15 @@
'lastSuiviIsPublic',
];

private array $deletedObjects;

public function __construct(
private HistoryEntryManager $historyEntryManager,
private EntityManagerInterface $entityManager,
private EntityComparator $entityComparator,
private LoggerInterface $logger,
private readonly HistoryEntryManager $historyEntryManager,
private readonly EntityManagerInterface $entityManager,
private readonly EntityComparator $entityComparator,
private readonly LoggerInterface $logger,
#[Autowire(env: 'HISTORY_TRACKING_ENABLE')]
private string $historyTrackingEnable,
private readonly string $historyTrackingEnable,
) {
}

Expand Down Expand Up @@ -102,13 +104,16 @@ protected function processEntity(LifecycleEventArgs $eventArgs, HistoryEntryEven
}
}
if (HistoryEntryEvent::DELETE === $event) {
$changes = $this->entityComparator->getEntityPropertiesAndValueNormalized($entity);
$className = $this->entityManager->getMetadataFactory()->getMetadataFor($entity::class)->getName();
if (!isset($this->deletedObjects[$className][$entity->getId()])) {
$this->deletedObjects[$className][$entity->getId()] = $entity;
$changes = $this->entityComparator->getEntityPropertiesAndValueNormalized($entity);
}
}

if (in_array($event, [HistoryEntryEvent::UPDATE, HistoryEntryEvent::DELETE]) && empty($changes)) {
return;
}

$this->saveEntityHistory($event, $entity, $changes);
}

Expand Down
Loading