diff --git a/src/EventSubscriber/AbstractAuditSubscriber.php b/src/EventSubscriber/AbstractAuditSubscriber.php index a064f1f..8c82902 100644 --- a/src/EventSubscriber/AbstractAuditSubscriber.php +++ b/src/EventSubscriber/AbstractAuditSubscriber.php @@ -18,6 +18,7 @@ use DateTimeInterface; use Doctrine\Common\Collections\Collection; use Doctrine\Common\EventSubscriber; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityNotFoundException; use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\Events; use Doctrine\ORM\UnitOfWork; @@ -432,7 +433,12 @@ abstract class AbstractAuditSubscriber implements EventSubscriber return; } - $fieldName = 'customField:'.$cfv->getCustomField()->getName(); + try { + $cfName = $cfv->getCustomField()->getName(); + } catch (EntityNotFoundException) { + return; + } + $fieldName = 'customField:'.$cfName; $diff = [$fieldName => ['from' => $from, 'to' => $to]]; $pendingUpdates[$ownerId] = $this->mergeDiffs($pendingUpdates[$ownerId] ?? [], $diff); diff --git a/src/Service/ReferenceAutoGenerator.php b/src/Service/ReferenceAutoGenerator.php index 31a31db..9e57f56 100644 --- a/src/Service/ReferenceAutoGenerator.php +++ b/src/Service/ReferenceAutoGenerator.php @@ -7,6 +7,7 @@ namespace App\Service; use App\Entity\Composant; use App\Entity\CustomFieldValue; use App\Entity\Piece; +use Doctrine\ORM\EntityNotFoundException; class ReferenceAutoGenerator { @@ -48,8 +49,12 @@ class ReferenceAutoGenerator /** @var CustomFieldValue $cfv */ foreach ($entity->getCustomFieldValues() as $cfv) { - $normalized = mb_strtoupper(trim($cfv->getValue())); - $map[$cfv->getCustomField()->getName()] = $normalized; + try { + $name = $cfv->getCustomField()->getName(); + } catch (EntityNotFoundException) { + continue; + } + $map[$name] = mb_strtoupper(trim($cfv->getValue())); } return $map;