Skip to content

Images are physically deleted after updating collection entity document #840

Open
@velkony

Description

@velkony

Images are physically deleted after updating collection entity document.
I saw that such a question was discussed here, but not for ODM.

I use S4 with vich/uploader-bundle - 1.8 and ODM.
Еverything works normally with a relation @mongodb\EmbedOne, but when I want to use a collection I noticed the following bug.

class Main {
.....

/**
* @MongoDB\EmbedMany(targetDocument="App\Document\MainPage\MoreFields", strategy="setArray")
*/
    private $moreFields;
// ..... other fields

=============================================================================================
/**
 * @MongoDB\EmbeddedDocument
 */
class MoreFields
{

/**
* @MongoDB\EmbedOne(targetDocument="App\Document\ImageDocument")
*/
     private $mainImage;
// ..... other fields

=============================================================================================
/**
 * @MongoDB\EmbeddedDocument
 * @Vich\Uploadable
 */
class ImageDocument
{
// ..... other fields

 /**
     * @MongoDB\Field(type="string")
     */
    protected $originalName;

    /**
     * @Vich\UploadableField(mapping="settings_image", fileNameProperty="imageName")
     *
     * @var File $imageFile
     */
    protected $imageFile;

    /**
     * @MongoDB\Field(type="string", name="image_name", nullable=true)
     */
    protected $imageName;

    /**
     * @MongoDB\Field(type="date")
     */
    protected $updatedAt;

    /**
     * @MongoDB\Field(type="string", name="image_alt", nullable=true)
     */
    protected $imageAlt;

    /**
     *
     * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
     */
    public function setImageFile(File $image = null)
    {
        $this->imageFile = $image;

        if ($image) {
            $this->updatedAt = new \DateTime('now');
        }

I tried the option to add a text field but without result
The collection rest in the database but the image is physically deleted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions