diff --git a/src/Controller/AdminPages/BaseAdminController.php b/src/Controller/AdminPages/BaseAdminController.php index 673ff574..8f3bb902 100644 --- a/src/Controller/AdminPages/BaseAdminController.php +++ b/src/Controller/AdminPages/BaseAdminController.php @@ -24,6 +24,7 @@ namespace App\Controller\AdminPages; use App\DataTables\LogDataTable; use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentContainingDBElement; use App\Entity\Attachments\AttachmentUpload; use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractNamedDBElement; @@ -190,6 +191,13 @@ abstract class BaseAdminController extends AbstractController } } + //Ensure that the master picture is still part of the attachments + if ($entity instanceof AttachmentContainingDBElement) { + if ($entity->getMasterPictureAttachment() !== null && !$entity->getAttachments()->contains($entity->getMasterPictureAttachment())) { + $entity->setMasterPictureAttachment(null); + } + } + $this->commentHelper->setMessage($form['log_comment']->getData()); $em->persist($entity); @@ -273,6 +281,14 @@ abstract class BaseAdminController extends AbstractController ); } } + + //Ensure that the master picture is still part of the attachments + if ($new_entity instanceof AttachmentContainingDBElement) { + if ($new_entity->getMasterPictureAttachment() !== null && !$new_entity->getAttachments()->contains($new_entity->getMasterPictureAttachment())) { + $new_entity->setMasterPictureAttachment(null); + } + } + $this->commentHelper->setMessage($form['log_comment']->getData()); $em->persist($new_entity); $em->flush(); diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 7f658cc0..20b07fd9 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -312,6 +312,11 @@ class PartController extends AbstractController } } + //Ensure that the master picture is still part of the attachments + if ($new_part->getMasterPictureAttachment() !== null && !$new_part->getAttachments()->contains($new_part->getMasterPictureAttachment())) { + $new_part->setMasterPictureAttachment(null); + } + $this->commentHelper->setMessage($form['log_comment']->getData()); $this->em->persist($new_part);