diff --git a/src/Entity/Attachments/AttachmentType.php b/src/Entity/Attachments/AttachmentType.php index c99ac392..5b7ca60f 100644 --- a/src/Entity/Attachments/AttachmentType.php +++ b/src/Entity/Attachments/AttachmentType.php @@ -63,6 +63,10 @@ class AttachmentType extends AbstractStructuralDBElement #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: AttachmentTypeAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** @var Collection */ #[Assert\Valid] @@ -70,9 +74,6 @@ class AttachmentType extends AbstractStructuralDBElement #[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])] protected Collection $parameters; - /** - * @var Collection - */ /** * @var Collection */ diff --git a/src/Entity/Base/MasterAttachmentTrait.php b/src/Entity/Base/MasterAttachmentTrait.php index 21168282..eaa34dc0 100644 --- a/src/Entity/Base/MasterAttachmentTrait.php +++ b/src/Entity/Base/MasterAttachmentTrait.php @@ -33,10 +33,10 @@ trait MasterAttachmentTrait { /** * @var Attachment|null + * Mapping is done in the subclasses (e.g. Part), like with the attachments. + * If this is done here (which is possible in theory), the attachment is not lazy loaded anymore, which causes unnecessary overhead. */ #[Assert\Expression('value == null or value.isPicture()', message: 'part.master_attachment.must_be_picture')] - #[ORM\ManyToOne(targetEntity: Attachment::class)] - #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] protected ?Attachment $master_picture_attachment = null; /** diff --git a/src/Entity/LabelSystem/LabelProfile.php b/src/Entity/LabelSystem/LabelProfile.php index 30429985..c729b661 100644 --- a/src/Entity/LabelSystem/LabelProfile.php +++ b/src/Entity/LabelSystem/LabelProfile.php @@ -41,6 +41,8 @@ declare(strict_types=1); namespace App\Entity\LabelSystem; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\LabelProfileRepository; use App\EntityListeners\TreeCacheInvalidationListener; use Doctrine\DBAL\Types\Types; @@ -68,6 +70,10 @@ class LabelProfile extends AttachmentContainingDBElement #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: AttachmentTypeAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** * @var LabelOptions */ diff --git a/src/Entity/Parts/Category.php b/src/Entity/Parts/Category.php index e5e3320e..23dd345c 100644 --- a/src/Entity/Parts/Category.php +++ b/src/Entity/Parts/Category.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace App\Entity\Parts; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\Parts\CategoryRepository; use Doctrine\DBAL\Types\Types; use Doctrine\Common\Collections\ArrayCollection; @@ -118,6 +120,10 @@ class Category extends AbstractPartsContainingDBElement #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: CategoryAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** @var Collection */ #[Assert\Valid] diff --git a/src/Entity/Parts/Footprint.php b/src/Entity/Parts/Footprint.php index 8138f967..ccd5bd9f 100644 --- a/src/Entity/Parts/Footprint.php +++ b/src/Entity/Parts/Footprint.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace App\Entity\Parts; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\Parts\FootprintRepository; use App\Entity\Base\AbstractStructuralDBElement; use Doctrine\Common\Collections\ArrayCollection; @@ -59,6 +61,10 @@ class Footprint extends AbstractPartsContainingDBElement #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: FootprintAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** * @var FootprintAttachment|null */ diff --git a/src/Entity/Parts/Manufacturer.php b/src/Entity/Parts/Manufacturer.php index b6768e4a..373ee950 100644 --- a/src/Entity/Parts/Manufacturer.php +++ b/src/Entity/Parts/Manufacturer.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace App\Entity\Parts; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\Parts\ManufacturerRepository; use App\Entity\Base\AbstractStructuralDBElement; use Doctrine\Common\Collections\ArrayCollection; @@ -59,6 +61,10 @@ class Manufacturer extends AbstractCompany #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: ManufacturerAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** @var Collection */ #[Assert\Valid] diff --git a/src/Entity/Parts/MeasurementUnit.php b/src/Entity/Parts/MeasurementUnit.php index 054056a8..ebb7b0d0 100644 --- a/src/Entity/Parts/MeasurementUnit.php +++ b/src/Entity/Parts/MeasurementUnit.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace App\Entity\Parts; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\Parts\MeasurementUnitRepository; use Doctrine\DBAL\Types\Types; use App\Entity\Base\AbstractStructuralDBElement; @@ -90,6 +92,10 @@ class MeasurementUnit extends AbstractPartsContainingDBElement #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: MeasurementUnitAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** @var Collection */ #[Assert\Valid] diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index 2826e5fe..e425e145 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace App\Entity\Parts; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\PartRepository; use Doctrine\DBAL\Types\Types; use App\Entity\Attachments\Attachment; @@ -102,7 +103,7 @@ class Part extends AttachmentContainingDBElement * @var Attachment|null */ #[Assert\Expression('value == null or value.isPicture()', message: 'part.master_attachment.must_be_picture')] - #[ORM\ManyToOne(targetEntity: Attachment::class)] + #[ORM\ManyToOne(targetEntity: PartAttachment::class)] #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] protected ?Attachment $master_picture_attachment = null; diff --git a/src/Entity/Parts/Storelocation.php b/src/Entity/Parts/Storelocation.php index 08c4911b..a519f6c1 100644 --- a/src/Entity/Parts/Storelocation.php +++ b/src/Entity/Parts/Storelocation.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace App\Entity\Parts; +use App\Entity\Attachments\Attachment; use App\Repository\Parts\StorelocationRepository; use Doctrine\DBAL\Types\Types; use Doctrine\Common\Collections\ArrayCollection; @@ -109,6 +110,10 @@ class Storelocation extends AbstractPartsContainingDBElement #[ORM\OneToMany(targetEntity: StorelocationAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: StorelocationAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /******************************************************************************** * * Getters diff --git a/src/Entity/Parts/Supplier.php b/src/Entity/Parts/Supplier.php index 34483ca3..b50bcd45 100644 --- a/src/Entity/Parts/Supplier.php +++ b/src/Entity/Parts/Supplier.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace App\Entity\Parts; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\Parts\SupplierRepository; use App\Entity\PriceInformations\Orderdetail; use Doctrine\Common\Collections\ArrayCollection; @@ -91,6 +93,10 @@ class Supplier extends AbstractCompany #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: SupplierAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** @var Collection */ #[Assert\Valid] diff --git a/src/Entity/PriceInformations/Currency.php b/src/Entity/PriceInformations/Currency.php index 548e45f6..6ad526a7 100644 --- a/src/Entity/PriceInformations/Currency.php +++ b/src/Entity/PriceInformations/Currency.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace App\Entity\PriceInformations; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\CurrencyRepository; use Doctrine\DBAL\Types\Types; use App\Entity\Attachments\CurrencyAttachment; @@ -84,6 +86,10 @@ class Currency extends AbstractStructuralDBElement #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: CurrencyAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** @var Collection */ #[Assert\Valid] diff --git a/src/Entity/ProjectSystem/Project.php b/src/Entity/ProjectSystem/Project.php index f202beaa..fd6ac8ba 100644 --- a/src/Entity/ProjectSystem/Project.php +++ b/src/Entity/ProjectSystem/Project.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace App\Entity\ProjectSystem; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\Parts\DeviceRepository; use App\Validator\Constraints\UniqueObjectCollection; use Doctrine\DBAL\Types\Types; @@ -93,6 +95,10 @@ class Project extends AbstractStructuralDBElement #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: ProjectAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** @var Collection */ #[ORM\OneToMany(targetEntity: ProjectParameter::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)] diff --git a/src/Entity/UserSystem/Group.php b/src/Entity/UserSystem/Group.php index b56cabf4..31c9c26a 100644 --- a/src/Entity/UserSystem/Group.php +++ b/src/Entity/UserSystem/Group.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace App\Entity\UserSystem; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Validator\Constraints\NoLockout; use Doctrine\DBAL\Types\Types; use App\Entity\Attachments\GroupAttachment; @@ -76,6 +78,10 @@ class Group extends AbstractStructuralDBElement implements HasPermissionsInterfa #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: GroupAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + #[Groups(['full'])] #[ORM\Embedded(class: PermissionData::class, columnPrefix: 'permissions_')] #[ValidPermission()] diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index 9abf7070..70121bf4 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace App\Entity\UserSystem; +use App\Entity\Attachments\Attachment; +use App\Entity\Attachments\AttachmentTypeAttachment; use App\Repository\UserRepository; use App\EntityListeners\TreeCacheInvalidationListener; use App\Validator\Constraints\NoLockout; @@ -226,6 +228,10 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; + #[ORM\OneToOne(targetEntity: UserAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + protected ?Attachment $master_picture_attachment = null; + /** @var \DateTimeInterface|null The time when the backup codes were generated */ #[Groups(['full'])]