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\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Event\OnFlushEventArgs;
|
use Doctrine\ORM\Event\OnFlushEventArgs;
|
||||||
use Doctrine\ORM\Events;
|
use Doctrine\ORM\Events;
|
||||||
use Doctrine\ORM\PersistentCollection;
|
|
||||||
use Doctrine\ORM\UnitOfWork;
|
use Doctrine\ORM\UnitOfWork;
|
||||||
use Error;
|
use Error;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
@@ -88,8 +87,7 @@ abstract class AbstractAuditSubscriber implements EventSubscriber
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this subscriber tracks constructeur collection changes.
|
* Whether this subscriber uses the complex onFlush path (collection + custom field tracking).
|
||||||
* Override to return true for entities with a constructeurs ManyToMany.
|
|
||||||
*/
|
*/
|
||||||
protected function hasCollectionTracking(): bool
|
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(
|
private function collectCollectionUpdate(
|
||||||
object $collection,
|
object $collection,
|
||||||
array &$pendingUpdates,
|
array &$pendingUpdates,
|
||||||
array &$pendingSnapshots,
|
array &$pendingSnapshots,
|
||||||
array &$pendingEntities,
|
array &$pendingEntities,
|
||||||
): void {
|
): 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function collectCustomFieldValueChanges(
|
private function collectCustomFieldValueChanges(
|
||||||
UnitOfWork $uow,
|
UnitOfWork $uow,
|
||||||
|
|||||||
@@ -79,14 +79,21 @@ final class ComposantAuditSubscriber extends AbstractAuditSubscriber
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'name' => $this->safeGet($entity, 'getName'),
|
'name' => $this->safeGet($entity, 'getName'),
|
||||||
'reference' => $this->safeGet($entity, 'getReference'),
|
'reference' => $this->safeGet($entity, 'getReference'),
|
||||||
'description' => $this->safeGet($entity, 'getDescription'),
|
'description' => $this->safeGet($entity, 'getDescription'),
|
||||||
'prix' => $this->safeGet($entity, 'getPrix'),
|
'prix' => $this->safeGet($entity, 'getPrix'),
|
||||||
'typeComposant' => $this->normalizeValue($this->safeGet($entity, 'getTypeComposant')),
|
'typeComposant' => $this->normalizeValue($this->safeGet($entity, 'getTypeComposant')),
|
||||||
'product' => $this->normalizeValue($this->safeGet($entity, 'getProduct')),
|
'product' => $this->normalizeValue($this->safeGet($entity, 'getProduct')),
|
||||||
'constructeurIds' => $this->normalizeCollection($entity->getConstructeurs()),
|
'constructeurIds' => array_map(
|
||||||
|
fn ($link) => [
|
||||||
|
'id' => $link->getConstructeur()->getId(),
|
||||||
|
'name' => $link->getConstructeur()->getName(),
|
||||||
|
'supplierReference' => $link->getSupplierReference(),
|
||||||
|
],
|
||||||
|
$entity->getConstructeurLinks()->toArray(),
|
||||||
|
),
|
||||||
'pieceSlots' => $pieceSlots,
|
'pieceSlots' => $pieceSlots,
|
||||||
'subcomponentSlots' => $subcomponentSlots,
|
'subcomponentSlots' => $subcomponentSlots,
|
||||||
'productSlots' => $productSlots,
|
'productSlots' => $productSlots,
|
||||||
|
|||||||
@@ -99,12 +99,19 @@ final class MachineAuditSubscriber extends AbstractAuditSubscriber
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'name' => $this->safeGet($entity, 'getName'),
|
'name' => $this->safeGet($entity, 'getName'),
|
||||||
'reference' => $this->safeGet($entity, 'getReference'),
|
'reference' => $this->safeGet($entity, 'getReference'),
|
||||||
'prix' => $this->safeGet($entity, 'getPrix'),
|
'prix' => $this->safeGet($entity, 'getPrix'),
|
||||||
'site' => $this->normalizeValue($this->safeGet($entity, 'getSite')),
|
'site' => $this->normalizeValue($this->safeGet($entity, 'getSite')),
|
||||||
'constructeurIds' => $this->normalizeCollection($entity->getConstructeurs()),
|
'constructeurIds' => array_map(
|
||||||
|
fn ($link) => [
|
||||||
|
'id' => $link->getConstructeur()->getId(),
|
||||||
|
'name' => $link->getConstructeur()->getName(),
|
||||||
|
'supplierReference' => $link->getSupplierReference(),
|
||||||
|
],
|
||||||
|
$entity->getConstructeurLinks()->toArray(),
|
||||||
|
),
|
||||||
'customFieldValues' => $customFieldValues,
|
'customFieldValues' => $customFieldValues,
|
||||||
'componentLinks' => $componentLinks,
|
'componentLinks' => $componentLinks,
|
||||||
'pieceLinks' => $pieceLinks,
|
'pieceLinks' => $pieceLinks,
|
||||||
|
|||||||
@@ -56,14 +56,21 @@ final class PieceAuditSubscriber extends AbstractAuditSubscriber
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'name' => $this->safeGet($entity, 'getName'),
|
'name' => $this->safeGet($entity, 'getName'),
|
||||||
'reference' => $this->safeGet($entity, 'getReference'),
|
'reference' => $this->safeGet($entity, 'getReference'),
|
||||||
'description' => $this->safeGet($entity, 'getDescription'),
|
'description' => $this->safeGet($entity, 'getDescription'),
|
||||||
'prix' => $this->safeGet($entity, 'getPrix'),
|
'prix' => $this->safeGet($entity, 'getPrix'),
|
||||||
'typePiece' => $this->normalizeValue($this->safeGet($entity, 'getTypePiece')),
|
'typePiece' => $this->normalizeValue($this->safeGet($entity, 'getTypePiece')),
|
||||||
'product' => $this->normalizeValue($this->safeGet($entity, 'getProduct')),
|
'product' => $this->normalizeValue($this->safeGet($entity, 'getProduct')),
|
||||||
'constructeurIds' => $this->normalizeCollection($entity->getConstructeurs()),
|
'constructeurIds' => array_map(
|
||||||
|
fn ($link) => [
|
||||||
|
'id' => $link->getConstructeur()->getId(),
|
||||||
|
'name' => $link->getConstructeur()->getName(),
|
||||||
|
'supplierReference' => $link->getSupplierReference(),
|
||||||
|
],
|
||||||
|
$entity->getConstructeurLinks()->toArray(),
|
||||||
|
),
|
||||||
'productSlots' => $productSlots,
|
'productSlots' => $productSlots,
|
||||||
'customFieldValues' => $customFieldValues,
|
'customFieldValues' => $customFieldValues,
|
||||||
'version' => $this->safeGet($entity, 'getVersion'),
|
'version' => $this->safeGet($entity, 'getVersion'),
|
||||||
|
|||||||
@@ -45,12 +45,19 @@ final class ProductAuditSubscriber extends AbstractAuditSubscriber
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'name' => $this->safeGet($entity, 'getName'),
|
'name' => $this->safeGet($entity, 'getName'),
|
||||||
'reference' => $this->safeGet($entity, 'getReference'),
|
'reference' => $this->safeGet($entity, 'getReference'),
|
||||||
'supplierPrice' => $this->safeGet($entity, 'getSupplierPrice'),
|
'supplierPrice' => $this->safeGet($entity, 'getSupplierPrice'),
|
||||||
'typeProduct' => $this->normalizeValue($this->safeGet($entity, 'getTypeProduct')),
|
'typeProduct' => $this->normalizeValue($this->safeGet($entity, 'getTypeProduct')),
|
||||||
'constructeurIds' => $this->normalizeCollection($entity->getConstructeurs()),
|
'constructeurIds' => array_map(
|
||||||
|
fn ($link) => [
|
||||||
|
'id' => $link->getConstructeur()->getId(),
|
||||||
|
'name' => $link->getConstructeur()->getName(),
|
||||||
|
'supplierReference' => $link->getSupplierReference(),
|
||||||
|
],
|
||||||
|
$entity->getConstructeurLinks()->toArray(),
|
||||||
|
),
|
||||||
'customFieldValues' => $customFieldValues,
|
'customFieldValues' => $customFieldValues,
|
||||||
'version' => $this->safeGet($entity, 'getVersion'),
|
'version' => $this->safeGet($entity, 'getVersion'),
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user