From: Raphaƫl Gertz Date: Sun, 3 Nov 2024 04:33:45 +0000 (+0100) Subject: Add album, user and path asset unique index X-Git-Tag: 0.0.7~11 X-Git-Url: https://git.rapsys.eu/treebundle/commitdiff_plain/ae572224add15c0e615fa068ed80cc679bb95182?hp=399693f8abe63c3a13d403105bbed688a9274d3d Add album, user and path asset unique index Rename resource to asset --- diff --git a/Entity/Resource.php b/Entity/Asset.php similarity index 75% rename from Entity/Resource.php rename to Entity/Asset.php index ca66734..666277d 100644 --- a/Entity/Resource.php +++ b/Entity/Asset.php @@ -16,11 +16,11 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Event\PreUpdateEventArgs; /** - * Resource + * Asset */ -class Resource { +class Asset { /** - * @var int + * @var ?int */ private ?int $id; @@ -37,9 +37,9 @@ class Resource { /** * Constructor * - * @param string $path The resource path + * @param ?string $path The asset path */ - public function __construct(private Album $album, private User $user, private string $path) { + public function __construct(private Album $album, private User $user, private ?string $path = null) { $this->created = new \DateTime('now'); $this->updated = new \DateTime('now'); } @@ -58,9 +58,9 @@ class Resource { * * @param \Rapsys\TreeBundle\Entity\Album $album * - * @return Resource + * @return Asset */ - public function setAlbum(Album $album): Resource { + public function setAlbum(Album $album): Asset { $this->album = $album; return $this; @@ -80,9 +80,9 @@ class Resource { * * @param \Rapsys\TreeBundle\Entity\User $user * - * @return Resource + * @return Asset */ - public function setUser(User $user): Resource { + public function setUser(User $user): Asset { $this->user = $user; return $this; @@ -100,11 +100,11 @@ class Resource { /** * Set path * - * @param string $path + * @param ?string $path * - * @return Resource + * @return Asset */ - public function setPath(string $path): Resource { + public function setPath(?string $path): Asset { $this->path = $path; return $this; @@ -113,9 +113,9 @@ class Resource { /** * Get path * - * @return string + * @return ?string */ - public function getPath(): string { + public function getPath(): ?string { return $this->path; } @@ -124,9 +124,9 @@ class Resource { * * @param \DateTime $created * - * @return Resource + * @return Asset */ - public function setCreated(\DateTime $created): Resource { + public function setCreated(\DateTime $created): Asset { $this->created = $created; return $this; @@ -146,9 +146,9 @@ class Resource { * * @param \DateTime $updated * - * @return Resource + * @return Asset */ - public function setUpdated(\DateTime $updated): Resource { + public function setUpdated(\DateTime $updated): Asset { $this->updated = $updated; return $this; @@ -166,9 +166,9 @@ class Resource { /** * {@inheritdoc} */ - public function preUpdate(PreUpdateEventArgs $eventArgs): ?Resource { + public function preUpdate(PreUpdateEventArgs $eventArgs): ?Asset { //Check that we have an snippet instance - if (($entity = $eventArgs->getEntity()) instanceof Resource) { + if (($entity = $eventArgs->getEntity()) instanceof Asset) { //Set updated value return $entity->setUpdated(new \DateTime('now')); } diff --git a/config/doctrine/Resource.orm.yml b/config/doctrine/Asset.orm.yml similarity index 67% rename from config/doctrine/Resource.orm.yml rename to config/doctrine/Asset.orm.yml index 710be18..0147e90 100644 --- a/config/doctrine/Resource.orm.yml +++ b/config/doctrine/Asset.orm.yml @@ -1,7 +1,7 @@ -Rapsys\TreeBundle\Entity\Resource: +Rapsys\TreeBundle\Entity\Asset: type: entity - #repositoryClass: Rapsys\TreeBundle\Repository\ResourceRepository - table: resources + #repositoryClass: Rapsys\TreeBundle\Repository\AssetRepository + table: assets id: id: type: integer @@ -21,9 +21,12 @@ Rapsys\TreeBundle\Entity\Resource: manyToOne: album: targetEntity: Rapsys\TreeBundle\Entity\Album - inversedBy: resources + inversedBy: assets user: targetEntity: Rapsys\TreeBundle\Entity\User - inversedBy: resources + inversedBy: assets + uniqueConstraints: + album_user_path: + columns: [ album_id, user_id, path ] lifecycleCallbacks: preUpdate: ['preUpdate']