EntityAuditBundle icon indicating copy to clipboard operation
EntityAuditBundle copied to clipboard

Support for translatable entities

Open pietaj opened this issue 3 years ago • 0 comments

Feature Request

The current state of the bundle does not support auditing entities which implement gedmo/knplabs translatable doctrine behaviors. I've started implementing the behavior, but encountered several issues that should be discussed beforehand.

  1. gedmo and knplabs load necessary locale data when doctrine postLoad event is fired. As audited entities are not loaded by doctrine, this event is never trigged. A solution might be to trigger the event manually, as loading audited entities should in my opinion simulate the same behavior as $someObjectRepository->find(), but this should be discussed. The code below works as expected
// SimpleThings\EntityAudit\AuditReader

private function createEntity($className, array $columnMap, array $data, $revision){

    ...
    $eventManager = $this->em->getEventManager();
    $eventArgs = new LifecycleEventArgs($entity, $this->em);
    $eventManager->dispatchEvent(Events::postLoad, $eventArgs);

    return $entity;
}
  1. the class SimpleThings\EntityAudit\Collection\AuditedCollection throws an exception when calling get($key) on a key that does not exist. This causes a failure if trying to fetch a audited translation with a locale that does not exist. The solution would be to return null (which is probably the expected behavior as Doctrine\Common\Collections\ReadableCollection suggests a @psalm-return T|null, but again this should be discussed

Before going any further, I would like to know your opinion if such a feature should be implemented. If yes, I would be happy to work on it

pietaj avatar Oct 07 '22 09:10 pietaj