]> Raphaël G. Git Repositories - treebundle/commitdiff
Add album, user and path asset unique index
authorRaphaël Gertz <git@rapsys.eu>
Sun, 3 Nov 2024 04:33:45 +0000 (05:33 +0100)
committerRaphaël Gertz <git@rapsys.eu>
Sun, 3 Nov 2024 04:33:45 +0000 (05:33 +0100)
Rename resource to asset

Entity/Asset.php [moved from Entity/Resource.php with 75% similarity]
config/doctrine/Asset.orm.yml [moved from config/doctrine/Resource.orm.yml with 67% similarity]

similarity index 75%
rename from Entity/Resource.php
rename to Entity/Asset.php
index ca66734554a804768e3c9bb2f071ab9b1b042504..666277d7bdf89a3fa264e7e82b263b96b0724e7e 100644 (file)
@@ -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'));
                }
similarity index 67%
rename from config/doctrine/Resource.orm.yml
rename to config/doctrine/Asset.orm.yml
index 710be18183d3d519fc6c3da58aa6486da2d69d7c..0147e90289cd8904bb5a9536fbc1f488fa2c2163 100644 (file)
@@ -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']