refactor(audit) : update audit subscribers to use ConstructeurLinks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,6 @@ use Doctrine\Common\EventSubscriber;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Event\OnFlushEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\ORM\PersistentCollection;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
use Error;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
@@ -88,8 +87,7 @@ abstract class AbstractAuditSubscriber implements EventSubscriber
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this subscriber tracks constructeur collection changes.
|
||||
* Override to return true for entities with a constructeurs ManyToMany.
|
||||
* Whether this subscriber uses the complex onFlush path (collection + custom field tracking).
|
||||
*/
|
||||
protected function hasCollectionTracking(): bool
|
||||
{
|
||||
@@ -413,50 +411,16 @@ abstract class AbstractAuditSubscriber implements EventSubscriber
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op: constructeurs are now tracked as ConstructeurLink entities (OneToMany),
|
||||
* so Doctrine no longer fires collection update events for them.
|
||||
*/
|
||||
private function collectCollectionUpdate(
|
||||
object $collection,
|
||||
array &$pendingUpdates,
|
||||
array &$pendingSnapshots,
|
||||
array &$pendingEntities,
|
||||
): void {
|
||||
if (!$collection instanceof PersistentCollection) {
|
||||
return;
|
||||
}
|
||||
|
||||
$owner = $collection->getOwner();
|
||||
if (null === $owner || !$this->supports($owner)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ownerId = (string) $owner->getId();
|
||||
if ('' === $ownerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mapping = $collection->getMapping();
|
||||
$fieldName = $mapping['fieldName'] ?? null;
|
||||
if ('constructeurs' !== $fieldName) {
|
||||
return;
|
||||
}
|
||||
|
||||
$before = $this->normalizeCollection($collection->getSnapshot());
|
||||
$after = $this->normalizeCollection($collection->toArray());
|
||||
|
||||
if ($before === $after) {
|
||||
return;
|
||||
}
|
||||
|
||||
$diff = [
|
||||
'constructeurIds' => [
|
||||
'from' => $before,
|
||||
'to' => $after,
|
||||
],
|
||||
];
|
||||
|
||||
$pendingUpdates[$ownerId] = $this->mergeDiffs($pendingUpdates[$ownerId] ?? [], $diff);
|
||||
$pendingSnapshots[$ownerId] = $this->snapshotEntity($owner);
|
||||
$pendingEntities[$ownerId] = $owner;
|
||||
}
|
||||
): void {}
|
||||
|
||||
private function collectCustomFieldValueChanges(
|
||||
UnitOfWork $uow,
|
||||
|
||||
@@ -79,14 +79,21 @@ final class ComposantAuditSubscriber extends AbstractAuditSubscriber
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $entity->getId(),
|
||||
'name' => $this->safeGet($entity, 'getName'),
|
||||
'reference' => $this->safeGet($entity, 'getReference'),
|
||||
'description' => $this->safeGet($entity, 'getDescription'),
|
||||
'prix' => $this->safeGet($entity, 'getPrix'),
|
||||
'typeComposant' => $this->normalizeValue($this->safeGet($entity, 'getTypeComposant')),
|
||||
'product' => $this->normalizeValue($this->safeGet($entity, 'getProduct')),
|
||||
'constructeurIds' => $this->normalizeCollection($entity->getConstructeurs()),
|
||||
'id' => $entity->getId(),
|
||||
'name' => $this->safeGet($entity, 'getName'),
|
||||
'reference' => $this->safeGet($entity, 'getReference'),
|
||||
'description' => $this->safeGet($entity, 'getDescription'),
|
||||
'prix' => $this->safeGet($entity, 'getPrix'),
|
||||
'typeComposant' => $this->normalizeValue($this->safeGet($entity, 'getTypeComposant')),
|
||||
'product' => $this->normalizeValue($this->safeGet($entity, 'getProduct')),
|
||||
'constructeurIds' => array_map(
|
||||
fn ($link) => [
|
||||
'id' => $link->getConstructeur()->getId(),
|
||||
'name' => $link->getConstructeur()->getName(),
|
||||
'supplierReference' => $link->getSupplierReference(),
|
||||
],
|
||||
$entity->getConstructeurLinks()->toArray(),
|
||||
),
|
||||
'pieceSlots' => $pieceSlots,
|
||||
'subcomponentSlots' => $subcomponentSlots,
|
||||
'productSlots' => $productSlots,
|
||||
|
||||
@@ -99,12 +99,19 @@ final class MachineAuditSubscriber extends AbstractAuditSubscriber
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $entity->getId(),
|
||||
'name' => $this->safeGet($entity, 'getName'),
|
||||
'reference' => $this->safeGet($entity, 'getReference'),
|
||||
'prix' => $this->safeGet($entity, 'getPrix'),
|
||||
'site' => $this->normalizeValue($this->safeGet($entity, 'getSite')),
|
||||
'constructeurIds' => $this->normalizeCollection($entity->getConstructeurs()),
|
||||
'id' => $entity->getId(),
|
||||
'name' => $this->safeGet($entity, 'getName'),
|
||||
'reference' => $this->safeGet($entity, 'getReference'),
|
||||
'prix' => $this->safeGet($entity, 'getPrix'),
|
||||
'site' => $this->normalizeValue($this->safeGet($entity, 'getSite')),
|
||||
'constructeurIds' => array_map(
|
||||
fn ($link) => [
|
||||
'id' => $link->getConstructeur()->getId(),
|
||||
'name' => $link->getConstructeur()->getName(),
|
||||
'supplierReference' => $link->getSupplierReference(),
|
||||
],
|
||||
$entity->getConstructeurLinks()->toArray(),
|
||||
),
|
||||
'customFieldValues' => $customFieldValues,
|
||||
'componentLinks' => $componentLinks,
|
||||
'pieceLinks' => $pieceLinks,
|
||||
|
||||
@@ -56,14 +56,21 @@ final class PieceAuditSubscriber extends AbstractAuditSubscriber
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $entity->getId(),
|
||||
'name' => $this->safeGet($entity, 'getName'),
|
||||
'reference' => $this->safeGet($entity, 'getReference'),
|
||||
'description' => $this->safeGet($entity, 'getDescription'),
|
||||
'prix' => $this->safeGet($entity, 'getPrix'),
|
||||
'typePiece' => $this->normalizeValue($this->safeGet($entity, 'getTypePiece')),
|
||||
'product' => $this->normalizeValue($this->safeGet($entity, 'getProduct')),
|
||||
'constructeurIds' => $this->normalizeCollection($entity->getConstructeurs()),
|
||||
'id' => $entity->getId(),
|
||||
'name' => $this->safeGet($entity, 'getName'),
|
||||
'reference' => $this->safeGet($entity, 'getReference'),
|
||||
'description' => $this->safeGet($entity, 'getDescription'),
|
||||
'prix' => $this->safeGet($entity, 'getPrix'),
|
||||
'typePiece' => $this->normalizeValue($this->safeGet($entity, 'getTypePiece')),
|
||||
'product' => $this->normalizeValue($this->safeGet($entity, 'getProduct')),
|
||||
'constructeurIds' => array_map(
|
||||
fn ($link) => [
|
||||
'id' => $link->getConstructeur()->getId(),
|
||||
'name' => $link->getConstructeur()->getName(),
|
||||
'supplierReference' => $link->getSupplierReference(),
|
||||
],
|
||||
$entity->getConstructeurLinks()->toArray(),
|
||||
),
|
||||
'productSlots' => $productSlots,
|
||||
'customFieldValues' => $customFieldValues,
|
||||
'version' => $this->safeGet($entity, 'getVersion'),
|
||||
|
||||
@@ -45,12 +45,19 @@ final class ProductAuditSubscriber extends AbstractAuditSubscriber
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $entity->getId(),
|
||||
'name' => $this->safeGet($entity, 'getName'),
|
||||
'reference' => $this->safeGet($entity, 'getReference'),
|
||||
'supplierPrice' => $this->safeGet($entity, 'getSupplierPrice'),
|
||||
'typeProduct' => $this->normalizeValue($this->safeGet($entity, 'getTypeProduct')),
|
||||
'constructeurIds' => $this->normalizeCollection($entity->getConstructeurs()),
|
||||
'id' => $entity->getId(),
|
||||
'name' => $this->safeGet($entity, 'getName'),
|
||||
'reference' => $this->safeGet($entity, 'getReference'),
|
||||
'supplierPrice' => $this->safeGet($entity, 'getSupplierPrice'),
|
||||
'typeProduct' => $this->normalizeValue($this->safeGet($entity, 'getTypeProduct')),
|
||||
'constructeurIds' => array_map(
|
||||
fn ($link) => [
|
||||
'id' => $link->getConstructeur()->getId(),
|
||||
'name' => $link->getConstructeur()->getName(),
|
||||
'supplierReference' => $link->getSupplierReference(),
|
||||
],
|
||||
$entity->getConstructeurLinks()->toArray(),
|
||||
),
|
||||
'customFieldValues' => $customFieldValues,
|
||||
'version' => $this->safeGet($entity, 'getVersion'),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user