Remove preview image attachment during if the attachment got deleted during cloning

This fixes issue #559
This commit is contained in:
Jan Böhmer 2024-03-10 01:19:52 +01:00
parent a792a140f7
commit 945fb9384e
2 changed files with 21 additions and 0 deletions

View file

@ -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();

View file

@ -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);