@@ -39,6 +39,38 @@ class Product
3939
4040See issue [ GH-123 ] ( https://github.com/dustin10/VichUploaderBundle/issues/123 )
4141
42+ ## Uploading files does not trigger Gedmo/DoctrineExtensions events
43+
44+ Similar to the issue above, because VichUploaderBundle relies on Doctrine's ` prePersist ` and
45+ ` preUpdate ` events which occur _ after_ Gedmo's use of the ` preFlush ` event to execute it's own
46+ handlers, it is not possible to use Gedmo's handlers to track changes for uploaded files. To be
47+ more specific, you cannot use ` Gedmo\Timestampable ` to track when a file is uploaded or changed.
48+ One solution for this is to update your timestamp property in your setters of the file and field
49+ properties; updating both is necessary to track delete and change actions.
50+
51+ ``` php
52+ #[Vich\UploadableField(mapping: 'custom_file', fileNameProperty: 'myField')]
53+ protected ?File $myFile = null;
54+
55+ #[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
56+ protected ?string $myField = null;
57+
58+ #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
59+ public private(set) ?\DateTime $myFieldUpdatedAt = null;
60+
61+ public function setMyFile(?File $file = null): void
62+ {
63+ $this->myFieldUpdatedAt = new \DateTime();
64+ $this->myFile = $file;
65+ }
66+
67+ public function setMyField(?string $myField = null): void
68+ {
69+ $this->myFieldUpdatedAt = new \DateTime();
70+ $this->myField = $myField;
71+ }
72+ ```
73+
4274## Image not deleted with cascade deletion and Doctrine
4375
4476Just check the following options: ` cascade={"remove"} ` and ` orphanRemoval=true ` .
0 commit comments