Browse Source

fix image management

Olivier Massot 6 months ago
parent
commit
0ef631b02f

+ 4 - 4
src/Entity/Core/File.php

@@ -75,14 +75,14 @@ class File
     /**
      * Slug du fichier (i.e. le chemin d'accès relatif).
      */
-    #[ORM\Column(length: 255)]
-    private string $slug;
+    #[ORM\Column(length: 255, nullable: true)]
+    private ?string $slug;
 
     /**
      * Chemin d'accès du fichier.
      */
-    #[ORM\Column(length: 255)]
-    private string $path;
+    #[ORM\Column(length: 255, nullable: true)]
+    private ?string $path;
 
     /**
      * Nom du fichier.

+ 1 - 1
src/Service/File/Factory/ImageFactory.php

@@ -30,7 +30,7 @@ class ImageFactory
     public function createImageContent(File $file, string $filterName): void
     {
         $filters_options = $this->getCropFilterOptions($file->getConfig());
-        $path = $file->getPath();
+        $path = $file->getSlug();
         $this->createAndStore($path, $filterName, $filters_options);
     }
 

+ 2 - 1
src/Service/File/Storage/LocalStorage.php

@@ -96,7 +96,7 @@ class LocalStorage implements FileStorageInterface
     public function getImageUrl(File $file, string $size, bool $relativePath): string
     {
         $filterName = $this->getFilterFromSizeAndConfig($size, !empty($file->getConfig()));
-        $path = $file->getPath();
+        $path = $file->getSlug();
 
         if (!$this->cacheManager->isStored($path, $filterName)) {
             try {
@@ -159,6 +159,7 @@ class LocalStorage implements FileStorageInterface
 
         $file = (new File())
             ->setName($filename)
+            ->setSlug(null)
             ->setOrganization($organization)
             ->setPerson($person)
             ->setType($type)